LINQ Include vs Join. Are they equivalent?

后端 未结 3 1552
庸人自扰
庸人自扰 2020-12-02 17:23

I have used join in linq to join 2 tables. What is the difference between a join and Include. From what I see, they both behave the same.

    Include vs. Joi         


        
3条回答
  •  时光取名叫无心
    2020-12-02 17:37

    In a sense, yes. Include is implemented as a join. Depending on the nullability of the included link it is an inner or left join.

    You can always build an include yourself by using a join, like this:

    db.Users.Select(u => new { u, u.City })
    

    This is an "include" for the user's city. It manifests itself as a SQL join.

提交回复
热议问题