如何将此查询表达式语法转换为方法语法?

时间:2011-02-11 12:07:27

标签: linq syntax methods

如何将此查询表达式语法转换为方法语法?请帮忙,

  var designers = (from d in _dbRead.Designer
                         join vd in _dbRead.VariationDesigner on d.DesignerId equals vd.DesignerId
                         join pv in _dbRead.ProductVariation on vd.VariationId equals pv.VariationId
                         where (pv.IsActive ?? false) && (d.SortName ?? "") != ""
                         orderby d.SortName
                         select d).Distinct();

2 个答案:

答案 0 :(得分:3)

我使用备忘单here

进行了转换

我在stackoverflow上的另一篇文章中发现了这一点。

这是灵魂:

objDbread.Designer.Where(x => (x.SortName ?? string.Empty) != string.Empty).Join(objDbread.VariationDesigner, x => x.DesignerId, x1 => x1.DesignerId, (x1, x2) => new { x1, x2 }).Join(objDbread.ProductVariation, x3 => x3.x2.VariationId, x4 => x4.VariationId, (x3, x4) => new { x3, x4 }).Where(x5 => (x5.x4.IsActive ?? false)).OrderBy(x5 => x5.x3.x1.SortName).Select(x5 => x5.x3.x1).Distinct().ToList();

答案 1 :(得分:1)

您需要获取LinqPad(www.linqpad.net)的副本并将查询粘贴到其中。您单击的按钮允许您查看相应的Method语法,编译器将所有Linq查询转换为。