Entity Framework - How do I join tables on non-primary key columns in secondary tables?

前端 未结 1 1185
陌清茗
陌清茗 2020-12-18 00:38

I want to join 2 tables using entity framework. I want the join to the second table to be on a non-primary key column.

e.g. I have a table Foo with fields



        
1条回答
  •  無奈伤痛
    2020-12-18 00:50

    Well you can't do this as a named relationship (i.e. the standard way).

    So this means the relationship is NOT part of the model.

    However you can still do a standard LINQ join though:

    from f in ctx.Foo
    join b in ctx.Bar on f.DbValue equals b.DbValue
    select new {f,b} 
    

    Hope this helps

    Check out my EF Tips series.

    0 讨论(0)
提交回复
热议问题