我在EF Code First中使用规范模式.当我通过操作进行排序时,VS会抛出一个新的异常
规范模式是从eShopOnWeb复制的
我只是改变了一点,这是我的更改代码:
public class Specification<T> : ISpecification<T>
{
public Expression<Func<T, object>> OrderBy { get; private set; }
public Specification(Expression<Func<T, bool>> criteria)
{
Criteria = criteria;
}
public Specification<T> OrderByFunc(Expression<Func<T, object>> orderByExpression)
{
OrderBy = orderByExpression;
return this;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的调用代码,它非常简单:
static void TestSpec()
{
var spec = new Specification<ExcelData>(x => x.RowIndex == 5)
.OrderByFunc(x => x.ColumnIndex);
using (var dbContext = new TechDbContext())
{
var top10Data = dbContext.ExcelData.Take(10).ToList();
var listExcel = dbContext.ApplySpecification(spec).ToList();
Console.WriteLine();
}
}
Run Code Online (Sandbox Code Playgroud)
如果我评论 …