0

我正在尝试在 LINQ 中为 EF5 构建查询。我的模型建立了一个有两个外键的关联,shippingcompanycontacts 有一个 contactid 和一个 shippingcompanyid。该“表”没有智能感知(它在 mySQL 中显示为表)我尝试以这种方式访问​​数据无济于事。(我硬编码了id)

 Dim testquery = (From s In ctx.shippingcompanies Where s.Id = 1 Join
                c In ctx.contacts On s.Id Equals c.Id Select New With {c.LastName}).ToList()

我真的需要访问关联表,但它没有智能感知

4

1 回答 1

2

The association table is not available in EF by default. You have only Contacts and ShippingCompanies and each of them contains navigation property to their related counter part so your query can be defined as (C#):

var query = from s in ctx.shippingcompanies 
            where s.Id == 1
            from c in s.contacts // accessing navigation property
            select c.LastName;

You can manually edit EDMX and bring ShippingCompanyContacts as a new entity but it is not usual way to use EF.

于 2013-01-04T09:21:58.097 回答