【问题标题】:How to create a dynamic INNER JOIN Multiple Colums如何创建动态 INNER JOIN 多列
【发布时间】:2016-01-20 13:13:25
【问题描述】:

我想为内部联接子句构建动态 Linq to Sql 查询,其中内部联接将包括多个用于联接的动态列。

以下是我需要动态实现的编译时查询:

var source = lParent.GroupJoin(lChild,
    p => new{ p.PID,p.CategoryId (These are dynamic columns)}
    c => new{ c.PID,c.CategoryId (These are dynamic columns)}
    (p, g) =>  new { Parent = p, Childs= g })

谢谢。

【问题讨论】:

  • “动态”是什么意思?用户会确定要加入哪些列,还是要重新使用具有不同联接的查询?拥有动态连接子句似乎很奇怪。

标签: linq


【解决方案1】:

您可以使用以下查询进行内部联接。 使用来自this linkGroupJoin 代码。

source.AsQueryable()
.GroupJoin(destination.AsQueryable(),
           outer.ToString(),
           inner.ToString(),
           "new (outer as sources, group as destinations)")
.SelectMany("destinations", "new(outer as sources, inner as destinations)");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-23
    • 1970-01-01
    • 2013-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-22
    • 1970-01-01
    相关资源
    最近更新 更多