简体   繁体   中英

Working directly with EntitySet?

I'm trying to wrap my head around all the classes present in Entity Framework 4. The only one that I'm confused by (so far) is EntitySet. EntitySets are never mentioned anywhere in the generated C# code from my .edmx files, only in the XML files (.csdl, .msl, .ssdl).

ObjectSet seems to be a wrapper around EntitySet (although it also exposes the EntitySet as a public property.) Are there any cases where I will be directly working with EntitySets?

From MSDN :

A logical container for entities of a given type and its subtypes. Entity sets are mapped to tables in a database.

Essentially, it's CSDL talk - as to which "set" of entities the objects are mapped to.

You don't need to worry about it - you'll be working with ObjectSet<T> :

var orders = ctx // ObjectContext
             .Orders // ObjectSet<Order>
             .SingleOrDefault(); // Order

For a bonus tip - if possible, use IObjectSet<T> to facilitate unit testing (implement a mock one - eg an in-memory static list).

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