2012-12-17 13 views
0

可能重复:
How to do a join in linq to sql with method syntax?如何使用join()方法表达

如何使用join()方法表达?

Here, my model edmx

/// <summary> 
    /// Searches the specified term. 
    /// </summary> 
    /// <param name="term">The term.</param> 
    /// <returns></returns> 
    public List<City> Search(string term, string countryAbbrev, string provinceAbbrev) 
    { 
     //if(!string.IsNullOrEmpty(country) && !string.IsNullOrEmpty(province)) 
     return context.Cities.join(????).Where(Cty => Cty.Name.Contains(term)).ToList(); 
    } 

我想与Provincecountry加入。我知道如何使用“From .. in .. join..”做,但没有与此表达Join(???)

+1

看看这个:http://stackoverflow.com/questions/3217669/how-to-do -a-join-in-linq-to-sql-with-method-syntax –

+0

非常感谢你!这是我的解决方案 –

回答

2

你不需要做,因为实体已经在关系的连接,使您可以使用导航属性获得的相关清单记录

例如让所有的城市的一个省,你可以做以下:

var citiesInProvince=context.Province.Single(x => x.id==*AnyID*) 
          .Cities; 
+0

是的,但我收到'ProvinceAbbrev'和'CountryAbbrev',我想用这些条款研究城市 –