开发者

Linq on a Datasource of list type

I have several entity objects for eg. Customer, Orders which derive from IComparable and all all mapped to database fields.

I bind the grid at runtime as a开发者_JS百科 List<Customer>, List<Orders> etc.

I am writing a custom column class where I can get Parent.DataSource (it would always be List<>) but the actual type is unknown. I need to convert that to a list type (maybe IList) so I could write linq queries against the datasource.

something like

IList t = Parent.DataSource as IList
var qry = from cl in t


You should be able to convert your Parent.DataSource into the appropriate type via LINQ's Cast() method, and query against it:

var query = from customer in Parent.DataSource.Cast<Customer>()
            where customer.Foo == "Bar"
            select customer;


you can use Cast in Linq .

var query = from customers in Parent.DataSource.Cast<Customer>()
            select customers;

Cast<Customer> will convert your Parent.DataSource to your corresponding Customer entity

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜