LINQ to SQL关联和独立项目 [英] LINQ to SQL Associations and seperated projects

查看:64
本文介绍了LINQ to SQL关联和独立项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我已经在使用LINQ2SQL了一段时间,并开始想知道在两个实体类之间建立的关联.

假设我在SQL数据库中有表A和B.在A和B之间存在1-M关系.代表表A和B的实体类在2个不同的项目中找到(我们称项目A(具有实体类A)和项目B(具有实体类B)) VS2010.B依靠A来做一些工作,但是出于明显的原因,只有B应该引用A.

当实现LINQ关联时,B必须具有EntityRef< A>.和A [必须(?)]具有EntitySet< B>.但是,这将导致循环依赖!!!那么正确的做法是根本不要从A引用B吗?具有EntitySet< B>是否真的有必要?在A?

解决方案

中,我从未使用过LinQ2SQL,但是当我创建自己的类时,我再也不会使用EntitySet<B>.例如,如果我有一个Customer对象,并且每个Customer与几个Order对象相关联,则我的Order类中有一个OrderCustomer属性,而我的Customer类中却没有一个List<Orders>.

好,所以我自己解决了这个问题:

引用我的问题:实现LINQ关联时,B必须具有EntityRef ,而A [必须(?)]必须具有EntitySet ."

A不需要具有EntitySet .所以我只是从A删除了EntitySet .没有循环依赖!!!


Hi there,

I have been playing around with LINQ2SQL for a bit now and started wondering about the Associations that one would make between two entity classes.

Let''s say I have Table A and B in a SQL Database. There exits a 1-M relationship between A and B. The entity classes that represent Tables A and B are found in 2 different Projects (let us call the Project A (has entity class A) and Project B (has entity class B) in VS2010. B depends on A to do some work, but for obvious reasons, only B should have a reference to A.

When implementing the LINQ Associations, B must have EntityRef<A> and A [must(?)] have EntitySet<B>. But this will cause a circular dependancy!!! So would the correct thing to do be not to reference B from A at all? Is it really that necessary to have an EntitySet<B> in A?

解决方案

I,ve never used LinQ2SQL, but when I create my own classes I never have an EntitySet<B>. For example, if I have a Customer object, and each Customer is associated with several Order objects, I have a OrderCustomer property in my Order class, but I never have a List<Orders> in my Customer class.


Ok so I kinda solved it myself:

to quote myself from my question: ''When implementing the LINQ Associations, B must have EntityRef and A [must(?)] have EntitySet.''

It is not required for A to have EntitySet. so I merely dropped EntitySet from A. No circular dependancy!!!


这篇关于LINQ to SQL关联和独立项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆