Linq-to-SQL 生成的实体可以移出数据上下文吗?
我们需要将 L2S 实体映射到 DTO,反之亦然。现在,我们的 L2S 实体位于数据项目中,而我们的域 (dto) 实体位于实体项目中。如果不创建循环引用,则执行映射是很困难的。如果两组实体位于同一个项目中,则实体可以将自身映射到彼此(L2S 到 DTO,反之亦然)。
有没有办法移动 L2S 实体,但将数据上下文保留在数据项目中?或者一般来说有更好的解决方案吗?
We need to map L2S entities to DTOs, and vice versa. Right now, our L2S entities are in a Data project, and our domain (dto) entities are in an Entities project.Performing a mapping is difficult without creating a circular reference. If both sets of entities lived in the same project, the entities could map themselves to each other (L2S to DTO and vice versa).
Is there a way to move the L2S entities, but leave the data context in the Data project? Or is there just a better solution to this, in general?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为 K Ivanov 的建议可能是处理这个问题的最简单方法;让 L2S 和 DTO 类(幸福地)彼此不知道,并且有第三个中心位置,其中任一方向的映射都在其中进行。
我还会问,为了防止强烈反对,我会稍微犹豫一下,但将项目分开是否真的能达到目的……或者只是让事情变得更加复杂。
I think what K Ivanov was suggesting is probably the easiest way to handle this; keep the L2S and DTO classes (blissfully) unaware of each other, and have a third, central place where the mapping in either direction goes.
I would also ask, with a tiny bit of a wince in case of backlash, but if keeping the projects separate is truly serving a purpose... or just making things more complex.