2012-04-24 86 views
0

我有以下查询如何将匿名类型转换为实体框架?

  var db = new Entities(); 
      IQueryable<Tbl_RSCRegularSupply> qrySupp = (from cont in db.Tbl_RSC 
                 where cont.ID == contractID 
                 let RegSupp = new 
                 { 
                  RegSupply = from R in cont.Tbl_RSCSupplyPlan 
                     select R.Tbl_RSCRegularSupply 
                 } 

                 select (Tbl_RSCRegularSupply)RegSupp.RegSupply); 


      return qrySupp.AsParallel().ToList(); 

但是只能执行这个创建以下例外。

无法强制类型'System.Collections.Generic.IEnumerable`1'键入'Tbl_RSCRegularSupply'。 LINQ to Entities仅支持投射实体数据模型基元类型。

这是从上面的查询中获得List<Tbl_RSCRegularSupply>的一些好方法。

回答

0

问题是RegSupp.RegSupplyIEnumerable<EntitySet<Tbl_RSCRegularSupply>>,所以它不能被转换为Tbl_RSCRegularSupply。换句话说,你有一个列表清单,而不是一个项目清单。

我不知道你的要求,但是你可以做

} ... select RegSupp.RegSupply.Selectmany(r => r)); 

其压平,结果在一个列表中。

+0

它并没有解决问题。我同意你,它返回的东西就像那个IEnumerable >但它如何可能得到列表 Shamim 2012-04-25 05:06:58

+0

'Selectmany'应该这样做......? (后跟ToList())。 – 2012-04-25 06:43:28

相关问题