[英]Loading partial entities with Linq to Entities
I am trying to load a partial entity with Linq to Entities: 我正在尝试使用Linq加载部分实体到实体:
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. " 我尝试了它,我得到以下NotSupportedException:“ 实体或复杂类型'CompleteKitchenModel.Contact'不能在LINQ to Entities查询中构造。 ”
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. 正如错误所述,您的语法不受支持。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.