- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我偶然发现了下一个问题......我有数据库上下文:
// For support unit testing...
public interface IDbContext : IDisposable
{
IQueryable<Hardware> Hardwares { get; }
IQueryable<ProviderHardware> ProviderHardwares { get; }
}
// Real DbContext (EF 4.0, Code First)
public class PrimaryDbContext : DbContext, IDbContext
{
public DbSet<Hardware> Hardwares { get; set; }
public DbSet<ProviderHardware> ProviderHardwares { get; set; }
IQueryable<Hardware> IDbContext.Hardwares
{ get { return Hardwares; } }
IQueryable<ProviderHardware> IDbContext.ProviderHardwares
{ get { return ProviderHardwares; } }
...
}
var hardwaresRemoved = db.Hardwares.Where(i => (i.IsAvailable == true) &&
(db.ProviderHardwares.Count(j => j.Article == i.Article) == 0)).ToList();
Unable to create a constant value of type 'ConfiguratorMvcApplication.DomainModels.ProviderHardware'. Only primitive types ('such as Int32, String, and Guid') are supported in this context.
最佳答案
我最终为每个 DbSet 提供了两个属性:一个是 IQueryable 类型,一个是 DbSet 类型。 IQueryable 属性在接口(interface)中定义,它将调用中继到具体实现(DbSet 类型的属性),如下所示:
// Exists in the interface
public IQueryable<AccountContact> AccountContacts
{
get
{
return DbAccountContacts;
}
set
{
DbAccountContacts = (DbSet<AccountContact>)value;
}
}
// Exists only in the implementation
public DbSet<AccountContact> DbAccountContacts { get; set; }
关于c#-4.0 - 使用 IQueryable<TEntity> 代替 DbSet<TEntity> 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7139352/
这应该很明显,但由于某种原因我无法弄清楚。所以在我的通用存储库类中,我有一个更新方法来更新实体: public void Update(TEntity entity) where TEntity :
我正在围绕 EF Core 编写一个小型包装器方法 DbSet .我有以下方法: public Task> GetAsync(Func, IQueryable> getFunction) {
我正在寻找一种将 Entity 和 TEntity 作为参数传递的方法,以便我可以将此方法用作通用方法。类似的东西: private void AttachSingleEntity(Entit
我想创建 Func, IOrderedQueryable>来自 SortingItems 的列表动态地。我的意思是我想创建以下表达式: entity => entity.OrderBy(c => c.
我正在使用这里提到的模式 http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/implementing-the-rep
我偶然发现了下一个问题......我有数据库上下文: // For support unit testing... public interface IDbContext : IDisposable
我有一个静态类 DataSource从文件中提取请求的数据并将其作为 List. 返回在 TestRepository (下),我正在使用通用 TEntity , 确定其类类型并从 DataSourc
我正在尝试将 DbLinq 与 SQLite 数据库一起使用,但在尝试转换 ITable 时遇到了问题作为Queryable . 在 DbLinq ( Issue 211 ) 中有一个已知的错误,这可
在 ms 文档中 Razor pages tutorial DbContext 有一个 DbSet Students 集 public class SchoolContext : DbContext
概述/描述 简单:从TEntity 中派生 的运行时类型对象的多态删除添加到 ObjectSet不会提高 IBindingList.ListChanged IBindingList 上的事件Objec
尝试将 Linq to SQL 用于我在家进行的一个小项目。我使用 dbmetal.exe(来自 DBLinq 项目)针对本地 MySQL 数据库生成了上下文代码和我的所有实体类。 一切都运行良好,但
似乎最简单的事情有时很难弄清楚...... 许多代码引用都具有 TEntity 类型,用于对实体数据模型中的实体进行一般处理。我试图在我的代码中使用它并得到:“未知类型'TEntity'”是什么给出的
更新: 我准备了一个通用函数来捕获数据库行以生成列表。我的方法就是这样的。 public class GenericDataAccess : IGenericRepository where
我想写一个通用的方法来返回任何模型,如产品、销售等。像这样的东西(.net 3.5;我不使用 Entity Framework ) public class ProductRepository : I
我想对存储库中的检索方法进行单元测试,该存储库具有模拟的 DbContext,但我无法将模拟的 DbSet 值设置到存储库。 存储库如下所示: public class ChangeLogReposi
我正在尝试讲述一种方法 GetAll()在模拟对象上 _portalUserRepositoryMock返回 IQueryable 类型的对象.我知道是这个类型,因为要测试的类中的方法返回这个类型。
我正在尝试: ... int id = 5; //DB is a instance of DbContext MethodInfo methodFind = DB.GetType().GetMetho
我有以下在 EF7 之前使用的界面。当我尝试使用 EF7 构建应用程序时,我收到以下错误,而且我似乎无法在任何地方找到这种类型。我非常感谢您就如何为 EF7 更改此代码提出建议。 Error CS02
这是我不相信的代码。请检查我如何将实体集合作为参数传递。 public ExamProduced GetExamProduced(XElement xml) { var examProduce
我正在尝试测试存储库的 Get 方法。签名如下: public virtual IEnumerable Get( Expression> filter = null,
我是一名优秀的程序员,十分优秀!