IQueryable<T>查询数据库问题
_LearnerRepository = new LearnerRepository(new GAS_VeristaEntities());
var learner = _LearnerRepository.GetThemAll();
_ClassInStudentRepository = new ClassInStudentRepository(new GAS_VeristaEntities());
var cisr = _ClassInStudentRepository.GetThemAll();
上面从数据库中取出两个表的所有行。
表结构类似
learner表包括列
LearnerID LearnerName ...
101
102
103
cisr表包括列
ClassinStudentID LearnerID ReceipNo
1 101 s
2 102 a
3 103 s
现在给出ReceipNo,获取对应的learner表的相应行。
if (!string.IsNullOrEmpty(searchString5)) //searchString5 为ReceiptNo
{
cisr = cisr.Where(u => u.RecieptNo == searchString5);
foreach (var id in cisr)
{
learner = learner.Where(u => u.LearnerID == id.LearnerID);
}
}
这样只能取出一行数据,如果查询ReceiptNo为s,怎么查出全部行
if (!string.IsNullOrEmpty(searchString5))
{
cisr = cisr.Where(u => u.RecieptNo == searchString5);
bool firsttime = true;
_LearnerRepository1 = new LearnerRepository(new GAS_VeristaEntities());
foreach (var id in cisr)
{
var learner1 = _LearnerRepository1.GetThemAll();
if (firsttime)
{
learner = learner.Where(u => u.LearnerID == id.LearnerID);
firsttime = false;
}
else
{
learner = learner.Union(learner1.Where(u => u.LearnerID == id.LearnerID));
}
}
firsttime = true;
}
这样试过,但learner类型有变化,后续
public PaginatedList(IQueryable<T> source, int pageIndex, int pageSize)
{
PageIndex = pageIndex;
PageSize = pageSize;
TotalCount = source.Count(); -------------这里出错。{"The specified L