简体   繁体   中英

Loading partial entities with Linq to Entities

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM