How to create a dynamic LINQ join extension method

前端 未结 3 1492
难免孤独
难免孤独 2020-11-27 13:55

There was a library of dynamic LINQ extensions methods released as a sample with Visual Studio 2008. I\'d like to extend it with a join method. The code below fail

3条回答
  •  爱一瞬间的悲伤
    2020-11-27 14:12

    You can install the nuget package of System.Linq.Dynamic.Core - https://github.com/StefH/System.Linq.Dynamic.Core

    This has the join method implemented along with various other helper methods.

    Using this library you can do a simple join in the following the way

    myContext.TableA.Join(myContext.TableB,'Id','TableAId','outer',null)

    in the result selector outer and inner are key words to access the result of the join.

    Using a key with multiple properties and/or selecting a result with multiple properties can be done in the following way

    myContext.TableA.Join(myContext.TableB,'new (Id as key1,Code as key2)','new (TableAId as key1,AnotherCol as key2)','new(outer.Id,inner.Desc)',null)

提交回复
热议问题