如何在类库中没有DbContext更新实体

时间:2015-07-22 22:02:16

标签: c# entity-framework entity-framework-6

如何在没有具体DbContext的情况下更新存储库中的实体?我试图通过声明一个接口,使库与DbContext实现完全分离:

public interface ISettingsManagerDbContext
{
    IDbSet<ApplicationSetting> ApplicationSettings { get; set; }

    int SaveChanges();
    Task<int> SaveChangesAsync();
    DbEntityEntry<TEntity> Entry<TEntity>(TEntity entity);
}

我一直收到以下错误:

The type 'TEntity' must be a reference type in order to use it as parameter 'TEntity' in the generic type or method 'System.Data.Entity.Infrastructure.DbEntityEntry<TEntity>'

关于如何在没有实际DbContext的情况下实现更新方法的任何建议?

1 个答案:

答案 0 :(得分:0)

基于该错误,我认为这意味着您需要这样做:

DbEntityEntry<TEntity> Entry<TEntity>(TEntity entity)
   where TEntity: class;

解决约束。基本上,where定义了TEntity必须是一个类的约束。

相关问题