日期:2014-05-17 浏览次数:20701 次
public class BaseEntity
{
public Guid Index{get;set;}
}
public class Test : BaseEntity
{
public string Name{get;set;}
public string Sort{get;set;}
}
var DbSet = DbContext.Tests; //Tests->DbSet<Test>
var result = DbSet.OrderBy(t=>t.Sort).ToArray();
DbSet = DbContext.Set<TEntity>();
//传进来的TEntity是Test类型,但是我们只知道是继承BaseEntity的
//result = ?
DbSet = DbContext.Set<TEntity>();
var express = Expression.Lambda<Func<TEntity, TKey>>(Expression.Convert(Expression.Property(Expression.Parameter(typeof(TEntity), "t"), typeof(TEntity).GetProperty("Sort")), typeof(object)), Expression.Parameter(typeof(TEntity), "t"));
result = DbSet.OrderBy(express).ToArray();