开发者

EF1 navigation properties not working?

My entity model was generated from the existing database. There is a many-to-many junction table picked up and hidden by EF.

EF1 navigation properties not working?

The relationship is definitely working because this query returns 2 users as expected.

    public IQueryable<User> FindUsersByGroupID(int group_id)
    {
        return db.Users.Where(u => 开发者_Go百科u.Groups.Any(g => g.Group_ID == group_id));
    }

But when locating a user that is part of the above result set the Groups navigation property count is 0. I shouldn't have to explicitly join.. right?

    public User FindUserByID(int id)
    {
        return db.Users.First(u => u.User_ID == id);
    }

EF1 navigation properties not working?


try

db.Users.Include("Groups").First(u => u.User_ID == id);

or load it after with

if (!user.Groups.IsLoaded)
{
    user.Groups.Load();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜