从条件= 2000
的Sometable中选择不同的描述我尝试使用反射实现此功能,但收到错误
500 Internal Server Error","error":"{\"message\":\"An error has occurred.\",\"exceptionMessage\":\"LINQ to Entities does not recognize the method 'System.Reflection.PropertyInfo[] GetProperties()' method, and this method cannot be translated into a store expression.
我用linq查询编写的方法
public IList<Material> GetDisctinctColumnValues(string parameter)
{
using (var db = this.dbFactory.CreateDbContext())
{
var columns= db.Table.GroupBy(m => ((IQueryable)m).ElementType.GetProperties().Where(p => p.Name == parameter))
.Select(c => c.FirstOrDefault()).ToList();
return columns;
}
}
我必须根据从方法传递的参数编写一个linq查询。假设Column作为参数传递,这里是“描述”。
答案 0 :(得分:0)
var res = Table
.Where(r => r.discreption==2000 })
.GroupBy(x => x.SomeProperty)
.Select(x => x.First());
或强>
var res = Table
.Where(r => r.discreption==2000 })
.Distinct().ToList();
如果您只想select
说明:
var res = Table.Select(z=>z.description)
.Where(r => r.description==2000 })
.GroupBy(x => x.SomeProperty)
.Select(x => x.First());
或强>
var res = Table.Select(z=>z.description)
.Where(r => r.description==2000 })
.Distinct().ToList();