我的 MVC 模型中的 linq 查询有问题。我有一个由 ObjectSet 和 EntityObject 组成的 edmx。这是我得到错误“来自CanaClie0012中的c ”的地方。当我去定义它去我的实体对象。
public class ClientRepository
{
public List<ClientSearchResult> Search(ClientSearchFilter filter, string sortColumn, string sortOrder, int pageSize, int pageIndex, out int totalRecords)
{
var q = from c in CanaClie0012
select new ClientSearchResult
{
Client00130012 = c.Client00130012,
F1Pais00200012 = c.F1Pais00200012,
F1Cana02530012 = c.F1Cana02530012,
Direcc0012 = c.Direcc0012,
};
if (!string.IsNullOrEmpty(filter.Client00130012))
{
q = q.Where(c => c.Client00130012.ToLower().Contains(filter.Client00130012.ToLower()));
}
if (!string.IsNullOrEmpty(filter.F1Pais00200012))
{
q = q.Where(c => c.F1Pais00200012.ToLower().Contains(filter.F1Pais00200012.ToLower()));
}
if (!string.IsNullOrEmpty(filter.F1Cana02530012))
{
q = q.Where(c => c.F1Cana02530012.ToLower().Contains(filter.F1Cana02530012.ToLower()));
}
if (!string.IsNullOrEmpty(filter.Direcc0012))
{
q = q.Where(c => c.F1Cana02530012.ToLower().Contains(filter.F1Cana02530012.ToLower()));
}
switch (sortColumn)
{
case "Client00130012":
q = (sortOrder == "desc") ? q.OrderByDescending(c => c.Client00130012) : q.OrderBy(c => c.Client00130012);
break;
case "F1Pais00200012":
q = (sortOrder == "desc") ? q.OrderByDescending(c => c.F1Pais00200012) : q.OrderBy(c => c.F1Pais00200012);
break;
case "Direcc0012":
q = (sortOrder == "desc") ? q.OrderByDescending(c => c.Direcc0012) : q.OrderBy(c => c.Direcc0012);
break;
case "F1Cana02530012":
q = (sortOrder == "desc") ? q.OrderByDescending(c => c.F1Cana02530012) : q.OrderBy(c => c.F1Cana02530012);
break;
default:
break;
}
totalRecords = q.Count();
return q.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
}
}
我已经尝试添加这个:
List<CanaClie0012> clients = new List<CanaClie0012>();
但它返回空值。请帮助我。我在这里迷路了。