使用Linq加载部分实体到实体 [英] Loading partial entities with Linq to Entities

查看:140
本文介绍了使用Linq加载部分实体到实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  Dim contacts = From c In My.Context。联系人_ 
选择新联系人{_
.ContactId = c.ContactId,_
.Name = c.Name
}

我尝试过,我得到以下NotSupportedException:实体或复合类型CompleteKitchenModel.Contact不能在LINQ to Entities中构建查询



谢谢

解决方案

必须使用匿名类型:

  Dim contacts = From c In My.Context.Contacts _ 
选择新建{_
.ContactId = c.ContactId,_
.Name = c.Name
}

然后将数据复制到联系人列表:

 对于每个联系人在联系人
Dim c与{.ContactId = c.ContactId,.Name = c.Name}的新联系
//添加到列表
Ne xt

不支持您的语法错误,


I am trying to load a partial entity with Linq to Entities:

Dim contacts = From c In My.Context.Contacts _
     Select New Contact With { _
         .ContactId = c.ContactId, _
         .Name = c.Name
     }

I tried it and I get the following NotSupportedException: "The entity or complex type 'CompleteKitchenModel.Contact' cannot be constructed in a LINQ to Entities query."

Thanks

解决方案

You'll have to use anonymous type:

Dim contacts = From c In My.Context.Contacts _
 Select New With { _
     .ContactId = c.ContactId, _
     .Name = c.Name
 }

and then copy data to Contact list:

For Each contact In contacts    
     Dim c As New Contact With { .ContactId = c.ContactId, .Name = c.Name}
     //Add to list
Next

Your syntax, as error says, is not supported.

这篇关于使用Linq加载部分实体到实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆