使用Linq加载部分实体到实体

编程入门 行业动态 更新时间:2024-10-22 20:32:39
本文介绍了使用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加载部分实体到实体

本文发布于:2023-06-03 10:05:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/473764.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:实体   加载   Linq

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!