【问题标题】:convert this LINQ code query to lambda expression将此 LINQ 代码查询转换为 lambda 表达式
【发布时间】:2016-06-06 23:38:52
【问题描述】:

我想用 lambda 表达式转换这段代码

 var employees = from e in dataContext.AccountTrees
                        where (id.HasValue ? e.ParentId == id : e.ParentId == null)
                        select new
                        {
                            id = e.AccountId,
                            Name = e.Name,
                            hasChildren = e.AccountTrees1.Any(),
                        };

【问题讨论】:

    标签: c# linq ef-code-first


    【解决方案1】:
     dataContext.AccountTrees.Where(e => id.HasValue ? e.ParentId.Value == id.Value : e.ParentId == null).Select(x => new {id = e.AccountId, Name = e.Name, hasChildren = e.AccountTrees1.Any()})
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多