Pobierz pojedyncze encje Framework Entity za pomocą zapytania LINQ lub GetObjectKey?
Wygląda na to, że GetObjectKey ma tę zaletę, że wyszukuje istniejące, instancje obiektów i TO magazyn danych. Wydaje się jednak, że tracisz część silnego pisania i musisz rzucić wynikowy obiekt:
GetObjectKey
<code>int customerID = 1; EntityKey key = new EntityKey("MyEntities.Customers", "CustomerID", customerID); Customer customer = context.GetObjectByKey(key) as Customer; </code>
vs. LINQ
<code>int customerID = 1; Customer customer = (from c in context.Customers where c.CustomerID = customerID select c).FirstOrDefault(); </code>
Osobiście wolę tę drugą metodę z powodu pisania. Ponadto Twój DAL będzie dość jednolity z wszystkimi metodami Get będącymi zapytaniami, chociaż to tylko osobiste preferencje.
Z czego korzystają chłopcy i dziewczęta?