实体框架加入 [英] entity framework join

查看:133
本文介绍了实体框架加入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个表(user,user_profile)在sql数据库中没有明确的关系。我不能将它添加到db。



所以,我不能这样做:

  db.user.include(user_profile)

属性在连接中,user_id



可以做这样的事情吗?

  db.user.join(user_profile On user.id = user_profile.user_id)

我可以这样做吗?



谢谢

解决方案

/ p>

 从u在db.user 
中加入db.user_profile中的u.id equals up.user_id
选择新的{u,up};


i have 2 table (user, user_profile) without a explicit relationship in the sql db. and i can't add it to the db.

so, i can't do this:

db.user.include("user_profile")

the attribute in for the join is user_id

is possible do anything like this?

db.user.join("user_profile On user.id = user_profile.user_id")

How can i do that?

thanks

解决方案

Try this :

from u in db.user
join up in db.user_profile on u.id equals up.user_id
select new { u, up};

这篇关于实体框架加入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆