我有一个带有EF解决方案的netCore,在上面还有运行时加载的插件。 每个插件都包含其模型,然后将其映射到EF。基本上在onModelCreating上,我扫描所有插件并传递modelBuilder,以便每个插件都可以将其模型添加到上下文中。
然后我有一个中央存储库,用于所有操作
public class EFRepository<Tcontext, T> : IRepository<T> where T : BaseEFModel where Tcontext : DbContext
{
private readonly DbContext context;
private DbSet<T> entity;
string errorMessage = string.Empty;
public EFRepository(Tcontext context)
{
this.context = context;
entity = context.Set<T>();
}
public IQueryable<T> GetEntity()
{
return entity;
}
}
例如,对于访问对象,我有类似的东西(我简化了下面的代码)
public class CuxDao : ICuxDao
{
private readonly IMapper mapper;
private IRepository<ClinicEFModel> clinicRepository;
private DbContext dbContext;
public CuxDao(IMapper mapper, EFDBContext dbContext)
{
this.mapper = mapper;
this.clinicRepository = new EFRepository<EFDBContext, ClinicEFModel>(dbContext);
}
public async Task<List<ClinicModel>> Getclinics()
{
var query = clinicRepository.GetEntity();
var clinics = await clinicRepository.GetQueryListAsync(query);
return this.mapper.Map<List<ClinicModel>>(clinics);
}
现在,我该代码是从插件执行的,我得到的错误是:
"Expression of type
'Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable'1[EntityFramework.Models.ClinicEFModel]'
cannot be used for return type
'System.Collections.Generic.IAsyncEnumerable'1[EntityFramework.Models.ClinicEFModel]'"}
完全相同的代码,如果它在主机中而不在插件中,则可以正常工作。
我缺少什么或做错了什么? 预先感谢