亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

.thenInclude用于Entity Framework Core 2中的子實體

.thenInclude用于Entity Framework Core 2中的子實體

C#
慕桂英546537 2021-05-20 18:13:04
以前(使用.net 4.5.2和EF 6時)。我有一個通用的Get方法,它接受了許多包括以下內容的方法;public abstract class DataContext : IdentityDbContext<ApplicationUser, ApplicationRole, int>, IDataContext{    public DataContext(DbContextOptions options)    : base(options)    {    }    // reduced for brevity    public T Get<T>(int id, params Expression<Func<T, object>>[] includes) where T : class, IEntity    {        return this.Set<T>().Include(includes).FirstOrDefault(x => x.Id == id);    }我再舉個例子。context.Get<Job>(id,     x => x.Equipment,    x => x.Equipment.Select(y => y.Type));包括Job.Equipment和在內Job.Equipment.Type。但是,當我將其移植到asp.net core 2上時,我嘗試了相同的通用方法,但是如果嘗試包含一個子實體,則會出現以下錯誤;屬性表達式“ x => {從x.Equipment select [y] .Type}中的設備y開始”無效。該表達式應表示屬性訪問:“ t => t.MyProperty”。有關包括相關數據的更多信息,請參見http://go.microsoft.com/fwlink/?LinkID=746393。誰能建議我如何解決這個問題,以便在Get<T>Entity Framework Core 2的通用方法中包含子實體?
查看完整描述

2 回答

  • 2 回答
  • 0 關注
  • 219 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號