日期:2014-05-20 浏览次数:20836 次
using (DBContext context = new DBContext())
{
return context.Roles.Where(r => r.OrgCode == orgCode).ToList();
}
using (DBContext context = new DBContext())
{
return context.Roles.ToList();
}
public static class EntitiesFilterHelper
{
public static IEnumerable<T> AutoFilter<T>(this IEnumerable<T> entities)
{
HttpContext context = HttpContext.Current;
if (context == null)
throw new InvalidOperationException();
NameValueCollection queryString = context.Request.QueryString;
string[] queryKeys = queryString.AllKeys;
foreach (string key in queryKeys)
{
PropertyInfo property = typeof(T).GetProperty(key, BindingFlags.Public
------解决方案--------------------
BindingFlags.Instance);
if (property == null)
continue;
entities = entities.Where(e =>
{
return property.GetValue(e, null).ToString() == queryString[key];
});
}
return entities;
}
}