views:

157

answers:

1

I just finished using Linq to Sql to map our existing Database structure for use in a Thick Client app.

While writing some Linq Methods to replace some Stored Procedures I noticed that sometimes I could do tblOne.tblTwo.MyDesiredField. I learned that there needed to be an association in the dbml for that to work. Well mine was missing some obvious ones so I added a bunch.

That was when I noticed that sometimes I couldn't do the above as some of the associated tables are considered EntitySets<tblThree> instead of the table, tblThree itself?

To me, there seems to be no rhyme or reason as to what I'll get. Am I doing something wrong in the dbml? Something I need to change in the Properties?

Is this cause for concern? I noticed that to use an EntitySet<tblThree> I need to add an extra from..

from person in context.tblPersons
from address in person.tblAddress where address.AddressType == "Home"
select new {person.Name, address.Home};
+1  A: 

EntitySet is a result set. If tableA has a 1 to many relationship with tableB then tableA.tableB refers to the collection of results in tableB that reference the result in tableA.

Table is just the table. If you drag and drop using the designer you'll see that it pluralizes the entitySets which makes things more readable.

EDIT: I imagine from the sounds of your setup, you'll likely see an entitySet as follows

from b in TableA select b.TableB

in this case TableA is a Table, and b.TableB is the EntitySet

David Archer
So it is the Many side of a 1 to Many relationship, correct? Also, nothing to be concerned about then. Is the extra `from` I illustrate above the correct way of working with `EntitySets<>` then? Thanks for the answer.
Refracted Paladin
Yes I would say what you are trying to do in that statement is "get me a list of everyone and their home address (because each person can have multiple addresses)
David Archer