0

I have a model

Retailer which has the fields

ID

Name

and another

Store

StoreName

RetailerID

In SQL to get the name of the retailer rather than just the ID when selecting all stores I can use a join.

How do I go about this in EF??

using (var context = new DBContext())
{    
//Get all stores with the name of the retailer
}

Thanks

4

1 回答 1

1

您可以简单地访问 Store 对象本身的相关 Retailer 对象,例如:

using(var context = new DBContext())
{
    var myStore = context.Stores.First(s => s.StoreName == "my store");
    string retailerName = myStore.Retailer.Name;
}
于 2013-10-29T23:01:40.840 回答