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>从上面的查询中获取是否有一些好方法。

4

1 回答 1

0

问题是那RegSupp.RegSupply是一个IEnumerable<EntitySet<Tbl_RSCRegularSupply>>,所以它不能被强制转换为Tbl_RSCRegularSupply。换句话说,您有一个列表列表,而不是项目列表。

我不知道你的规格,但你可以做

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

它将结果展平在一个列表中。

于 2012-04-24T11:29:43.330 回答