开发者

How to write this query as lambda expression?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜