“System.NotSupportedException”类型的异常在 System.Data.Entity.dll 中发生,但未在用户代码中进行处理 其他信息: 在 LINQ to Entitie

来源:互联网 发布:淘宝话题怎么玩 编辑:程序博客网 时间:2024/06/05 07:16

“System.NotSupportedException”类型的异常在 System.Data.Entity.dll 中发生,但未在用户代码中进行处理

其他信息: 在 LINQ to Entities 查询中无法构造实体或复杂类型“**Model.**Entity”。

出现原因:

EF中有实体EntityA,对实体进行扩展,比如增加了一个字段PropertyA

Public partial class EntityA

{

   [DataMember]

        public string PropertyA{ get; set; }

}

然后在service端进行如下调用时出现此错误。

   var q =        from c in EntityA        join p in EntityB on c equals p.Category        select new EntityA{ PropertyA= p.ProductName };

解决方法:

把 select new 的EntityA去掉即可。如下:

 var q =        from c in EntityA        join p in EntityB on c equals p.Category        select new { PropertyA= p.ProductName };

0 0
原创粉丝点击