ID CountryName
1 New Zealand
2 United States
3 Australia
4 United Kingdom
5 Europe
6 Japan另一个表是:
ID CountryId TypeId
1 1 1
2 1 2
3 1 3
4 2 1
5 2 2
6 2 3
7 3 1
8 3 2
9 3 3
10 4 1
11 4 2
12 4 3
13 5 1
14 5 2
15 5 3
16 6 1
17 6 2
18 6 3第一个表叫Country,第2个表叫MarketRate,现在我要通过根据MarketRate表中存在的所有的CountryId,来获取对应的Country表信息。如何写Linq to Entity?如果直接写SQL语句就很好写 select * from Country inner join MarketRate on Country.ID=MarketRate.CountryId但是Linq to Entity我不会写
比如EntitySet代表Country,如何写?
EntitySet.Where(c=>c.ID.....??

解决方案 »

  1.   

    select * from Country inner join MarketRate on Country.ID=MarketRate.CountryIdvar query=from c in db.EntitySet
              join m in db.MarketRate on c.ID equals m.CountryId into t1
              from p in t1.DefaultIfEmpty()
              select new
              {
                 ID=c.ID,
                 .........
              }; 
      

  2.   

    sorry,inner join,这样var query=from c in db.EntitySet
              join m in db.MarketRate on c.ID equals m.CountryId 
              select new
              {
                 ID=c.ID,
                 .........
              };
      

  3.   


    我是不是可以这样写:
    AllEntities代表IQueryable<Country>
        AllEntities().Where(e =>
                            e.MarketRates.Any(
                                et => et.CountryId==e.ID) 
    这样出来,会产生重复行吗?