+1 800 256 3608 (toll-free in North America) or +49 7531 90 60 10| service@combit.com

Binding to Entity Framework Objects

(combit Team) #1
Valid from List & Label 15
The ObjectDataProvider can be used to bind to Entity Framework data sources.

C# Sample:
//Initialize ObjectContext
using (testEntity AWEntity = new testEntity())
    //Get ObjectSet
    ObjectSet<Product> products = AWEntity.Products;
    //Define query
    IQueryable<Product> theQuery = from Product in products select Product;
    //Bind to query
    LL.DataSource = new ObjectDataProvider(theQuery,2);
    //Start Designer

If the data source structure is rather simple, you can also bind directly to the query:

LL.DataSource = theQuery; 

However, keep in mind that this will parse all relations up to the tenth level. If you’re dealing with a more complex data structure you should use the ObjectDataProvider and restrict the parsing to a certain level (second level in this sample):

LL.DataSource = new ObjectDataProvider(theQuery,2); 

When using EntityCollection objects as data source the ObjectDataProvider first checks the state of the sub relation by the IsLoaded property and dynamically calls Load() if necessary - the data is provided when needed.

IDKBTE000765 KBTE000765