开发者

What makes a LINQ Association an EntitySet<table>?

开发者 https://www.devze.com 2022-12-28 09:30 出处:网络
I just finished using Linq to Sql to map our existing Database structure for use in a Thick Client app.

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开发者_JAVA技巧 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};


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号