Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
Posted
Updated 6-Oct-11 21:21pm
v2

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.
 
Share this answer
 
Comments
PJ du Preez 7-Oct-11 4:00am    
Yes, my initial model did use List<t>. but with LINQ2SQL you use the entityset\ref as to accommodate the associations mapped by LINQ
Wayne Gaylard 7-Oct-11 4:06am    
Yeah, that was just used as an example. These days I use WPF and so use ObservableCollection for storing collections. I still think generating classes by hand, while tedious, is still better in the end. Especially when you need to start doing things that start getting complicated.
PJ du Preez 7-Oct-11 4:18am    
That's pretty cool, we're using LINQ as an ORM\DAL. The generated code sucks eggs so it's all manually typed.
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!!!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900