public class News
{
public int ID { get; set; }
public string Title { get; set; }
public List<Role> RoleList { get; set; }
}
public class Role
{
public int ID { get; set; }
public string Title { get; set; }
public List<User> UserList { get; set; }
public List<News> NewsList { get; set; }
}
public class User
{
public int ID { get; set; }
public string Name { get; set; }
public List<Role> RoleList { get; set; }
}
在不使用core ThenInclude的前提下
目前是只能獲取到 news 里面的Role 但是想再獲取 User 就查不到了
using(DataContext dataContext = new DataContext()){
List<News> news = dataContext.News.AsNbTracking().Include(d=>d.RoleList).ToList()
}
我還需要Role里面的User集合 請問應該需要怎么寫
uj5u.com熱心網友回復:
舉個例子主要是設定 ForeignKey
public partial class WD_MyProject
{
[Key]
public int id { get; set; }
public int uid { get; set; }
[ForeignKey("uid")]
public virtual WD_Employee WD_Employee { get; set; }
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/275621.html
標籤:C#
上一篇:Response.ContentType = "video/mp4"的檔案打開會播放視頻,其他視頻格式打開就是下載呢
