我正在使用 linq to Entity 通过加入它们来从不同的表中检索数据,但我也想按字段issueDesc对它们进行分组,以消除同一问题的不必要的重复条目。
这是代码:
using (AssistantEntities context = new AssistantEntities())
{
var problems = context.tblProblems;
var customers = context.tblCustomers;
var query =
from problem in problems
join customer in customers
on problem.CustID equals customer.custID
where problem.IsActive == true
orderby customer.isMonthlyService == true descending
select new
{
problemID = problem.problemID,
ProblemCreateDate = problem.ProblemCreateDate,
CustID = problem.CustID,
name = customer.name,
isMonthlyService = customer.isMonthlyService,
StationName = problem.StationName,
problemDesc = problem.problemDesc,
LogMeIn = problem.LogMeIn
};
return query.ToList();
}
我正在做 query.toList() 以便在 gridview 中使用该列表作为数据源。如果可能的话,还添加一个计算重复问题的字段。