2
林遇到实体框架时遇到问题。所选对象的对象属性为空
这里是我的代码:
var activeScoreList = (from s in context.Score
join i in context.Import on s.import.importId equals i.importId
where i.isActive.Value == 1
select s).ToList();
foreach (Score s in activeScoreList)
{
if (s.User.userId == loggedOnUserId) { // Here
...
}
}
我在我的数据库中的几个Score
对象和外键UserId
是NOT NULL
。
但是,在if
行始终是例外。 User
属性总是null
。
我是Linq的新手,所以我可能错过了配置的地方。这种行为是否正常?我必须为每个分数进行一次新查询才能获得User
对象吗?
谢谢,我不知道Include()方法! – madprog