以前(使用.net 4.5.2和EF 6時)。我有一個通用的Get方法,它接受了許多包括以下內(nèi)容的方法;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和在內(nèi)Job.Equipment.Type。但是,當我將其移植到asp.net core 2上時,我嘗試了相同的通用方法,但是如果嘗試包含一個子實體,則會出現(xiàn)以下錯誤;屬性表達式“ x => {從x.Equipment select [y] .Type}中的設(shè)備y開始”無效。該表達式應表示屬性訪問:“ t => t.MyProperty”。有關(guān)包括相關(guān)數(shù)據(jù)的更多信息,請參見http://go.microsoft.com/fwlink/?LinkID=746393。誰能建議我如何解決這個問題,以便在Get<T>Entity Framework Core 2的通用方法中包含子實體?
- 2 回答
- 0 關(guān)注
- 216 瀏覽
添加回答
舉報
0/150
提交
取消