【发布时间】:2013-03-18 20:20:43
【问题描述】:
我正在尝试创建通用Repository pattern 基类,从中将实现成员。这是一个代码:
public abstract class RepositoryBase<TEntity, TType> : IRepository<TEntity, TType>
where TEntity : EntityBase<TType>
{
public IAdNetMsSqlContext Context { get; set; }
public DbSet<TEntity> DbSet { get; set; }
public RepositoryBase(IAdNetMsSqlContext context)
{
Context = context;
DbSet = context.Set<TEntity>();
}
public IQueryable<TEntity> Get(TType id)
{
//!!! Here is an error
return DbSet.FirstOrDefault(e => e.Id == id);
}
....
}
我得到了错误:
Error 1 Operator '==' cannot be applied to operands of type 'TType' and `'TType' .... AdNet.Common.Base
行内:
return DbSet.FirstOrDefault(e => e.Id == id);
我不知道该怎么想。 TType 肯定等于 TType。
感谢任何提前!
【问题讨论】:
-
此时
TType的用途是什么? -
应该是Entity的通用类型,比如
Int32, Int64, Guid...。