我正在尝试使用Linq加载部分实体到实体:
Dim contacts = From c In My.Context.Contacts _
Select New Contact With { _
.ContactId = c.ContactId, _
.Name = c.Name
}
我尝试了它并得到以下NotSupportedException:“无法在LINQ to Entities查询中构造实体或复杂类型'CompleteKitchenModel.Contact'。”
由于
答案 0 :(得分:2)
您必须使用匿名类型:
Dim contacts = From c In My.Context.Contacts _
Select New With { _
.ContactId = c.ContactId, _
.Name = c.Name
}
然后将数据复制到联系人列表:
For Each contact In contacts
Dim c As New Contact With { .ContactId = c.ContactId, .Name = c.Name}
//Add to list
Next
不支持您的语法,如错误所示。