我有两个型号。 ApplicationUser
:实体框架的关系破裂
public class ApplicationUser : IdentityUser
{
public string FirstName { get; set; }
public DateTime AccountCreationDate { get; set; }
public virtual ICollection<ProfileView> ProfilesViewed { get; set; }
}
而且ProfileView
:
public class ProfileView
{
public int Id { get; set; }
public DateTime ViewDate { get; set; }
public virtual ApplicationUser Viewer { get; set; }
public virtual ApplicationUser Viewee { get; set; }
}
实体框架似乎正确创建我的表。我可以做以下和检索用户的ProfileViews
:
db.ProfileViews.Where(p => p.Viewer.Id == currentUser.Id);
我的问题是,我似乎无法做到以下几点:
db.Users
.Where(u => u.Id == currentUser.Id)
.Include(u => u.ProfilesViewed);
该用户以上的回报null
,即使它是Viewer
和几个ProfileView
一个Viewee
。
我跑我的所有用户foreach
,他们都不具有任何ProfilesViewed
如果我查询他们从Users
表Include
。我只能从ProfileViews
表中检索ProfileViews
...
任何人都有任何想法如何解决这个问题?
更重要的是,ApplicationUser的PK是什么?这种关系的映射是什么? – DevilSuichiro