2010-01-06 16 views
5

Ich versuche, eine Teil-Einheit mit Linq to Entities laden:Laden Teileinheiten mit Linq to Entities

Dim contacts = From c In My.Context.Contacts _ 
    Select New Contact With { _ 
     .ContactId = c.ContactId, _ 
     .Name = c.Name 
    } 

ich es versucht, und ich erhalte die folgende NotSupportedException: "Unternehmen oder komplexen Typ‚CompleteKitchenModel. Kontakt‘kann nicht in einer LINQ to Entities-Abfrage konstruiert werden"

Dank

Antwort

2

Sie werden anonymen Typ verwenden.

und kopieren Datenliste Kontakt:

For Each contact In contacts  
    Dim c As New Contact With { .ContactId = c.ContactId, .Name = c.Name} 
    //Add to list 
Next 

Ihre Syntax, wie Fehler sagt, wird nicht unterstützt.

+0

sux, aber ich muss zustimmen, danke. – Shimmy

+1

+1. Alternativ projizieren Sie auf ein POCO, das in L2E unterstützt wird. –

+0

@Craig Fisher: Und wo habe ich etwas über Syntaxfehler geschrieben? – LukLed