开发者

How to write this query as lambda expression?

开发者 https://www.devze.com 2022-12-15 20:52 出处:网络
I\'m still having problems to write lambda expressions that should create some object and to set properties with the object initializer.

I'm still having problems to write lambda expressions that should create some object and to set properties with the object initializer.

How would this query be written as a lambda expression?

List<CategoryContainer> _catLis开发者_StackOverflow中文版t = (from q in _dc.Category
                                   select new CategoryContainer
                                   {
                                     IDCategory = q.IDCategory,
                                   }).ToList();


Like this:

dc.Category.Select(q => new CategoryContainer {
                       IDCategory = q.IDCategory,
                   }).ToList();


Another option is ConvertAll:

dc.Category.ConvertAll<CategoryContainer>( q => new CategoryContainer { 
IDCategory = q.IDCategory, }).ToList();
0

精彩评论

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