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();
精彩评论