本文介绍了使用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 NextYour syntax, as error says, is not supported.
更多推荐
使用Linq加载部分实体到实体
发布评论