views:

28

answers:

1

Hi all..

I'm doing data binding with entity framework. I have three master-detail-sub models: Customers, Orders, and OrdersDetails. This would be run fine and data binding doing great:

this.customerBindingSource.DataSource = context.Customers.ToList();

But sure that would return all columns. How can I return specified columns and still preserving the binding? Something like this would fail:

context.Customers.Select(c => new { Name = c.Name, Address = c.Address });

Thank you..

A: 

I expect that you have to return all columns because EF must build entities from those data. If you use anonymos type with subset of columns you are doing projection to cutom type which is not related to your entity model. It should be responsibility of UI control which columns will be displayed. If you don't like this approach you have to define new set of entities with limited set of columns, map those entities in your EF model and return those entities from query to your BindingSource.

Ladislav Mrnka
So there are 2 options:1. removes unwanted columns from the data grid.2. creates new View map for the entities.Thank you, Ladislav :)
Elisa Hadi