我是 EntityFramework 的新手,所以这个问题可能有点愚蠢,但我试图搜索谷歌却一无所获。
我在数据库中有一张桌子:
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public Guid Id { get; set; }
[Required]
public UserProfile Owner { get; set; }
[Required]
public string Mask { get; set; }
[Required]
public string Key { get; set; }
public DateTime Generated { get; set; }
public DateTime DateTo { get; set; }
public bool isElite { get; set; }
其中 UserProfile Owner 是指向另一个表的链接。当我做出这样的选择时:
db.Keys.Where(s=>s.Owner.UserId == WebSecurity.CurrentUserId && s.DateTo > DateTime.UtcNow).ToList()
它运作良好,但是当我试图从许可证中联系所有者时,它总是为空。有人可以帮助如何获得所有者的许可证吗?感谢您的时间!
编辑:我认为我犯了一个错误,并且有点错误地发布了一个问题。我真正需要的是当我通过它的 ID 搜索许可证时:
License license = db.Keys.Find(id);
我可以让所有者喜欢:
var a = license.Owner;
我以前使用过 Active Record,并且它“按需”加载这些数据(仅当我调用它时)。我可以用 EF 以某种方式做到这一点吗?