03.25.10
Entity Framework
Dem Entity Framework ein wenig auf die Finger schauen: Entity Framework Profiler.
Dem Entity Framework ein wenig auf die Finger schauen: Entity Framework Profiler.
Der Fehler “cannot convert lambda expression to type ‘string’ because it is not a delegate type” tritt auch auf, wenn das Using Statement für System.Linq fehlt.
Wenn man die nicht explizit lädt, sind die Eigenschaften null. Daher vor dem Zugriff mit IsLoaded Überprüfen oder direkt nachdem das Entity Objekt geladen wurde die Verknüpfungen nachladen. Ist auf jeden Fall eine Stolperfalle.
Kollegen haben mal einen einfachen Wettbewerb Entity Framework vs. handcrafted SQL laufenlassen – ja 8. Mio DS in der Haupttabelle mit Verknüpfung. Ich hätte ja gegen EF gewettet, aber: es hat sich sehr gut gemacht. Die einfache Abfrage war bei EF deutlich effizienter als ein erster Ansatz mit T-SQL. Obwohl dieser “korrekter” (LEFT JOIN vs. Select * from (Select from * from … where …)) aussah. Gewonnen hatte handcrafted SQL als es dann darum ging die 100 Zeilen ab der 10.000. Zeile zu erfragen. Gegen eine temporäre Tabelle hatte EF da keine Chance. Bleibt abzwarten, wie’s mit EF4 wird.
Der Datentype ist zwar unterstützt, aber leider unterstützt EF NEWGUID() als Defaultvalue nicht
17.4.Can I use a server-generated guid as my entity key?
Unfortunately, in v1 of the EF this is not supported. While it is possible with SQL Server to have a column of type “uniqueidentifier” and to set it’s default value to be “newid()”, with SQL Server 2000 there’s no good way to extract the value that the server generated at the time you do the insert. This can be done on more recent versions of SQL Server, though, so the intent is that we should find a clean way to special case this support in future versions of the EF so it can be supported on those databases that allow it and not on others. For now, the work around is to generate the guid on the client (ideally in the constructor of your object) rather than on the server.
Aus: Entity Framework FAQ