开发者

Selecting columns in entity framework data binding

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.customerBindin开发者_运维百科gSource.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..


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜