0

Possible Duplicate:
How to do a join in linq to sql with method syntax?

How do I use join() expression?

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();
    }

I would like to join with Province and country. I know How to do with "From .. in .. join.." but not with this Expression Join(???)

Community
  • 1
  • 1
Olivier Albertini
  • 684
  • 2
  • 6
  • 22

1 Answers1

2

you don't need to do the join as the entities are already in relationship so you can use the navigation properties to get a list of related records

For example to get all the cities for a province you can do the below:

var citiesInProvince=context.Province.Single(x => x.id==*AnyID*)
                             .Cities;
Massimiliano Peluso
  • 26,379
  • 6
  • 61
  • 70