The below function returns all the rows in Files table even when the where filter if applied,
public IList<File> SearchFiles(int? FileID, int? type, int? Status)
{
var files = from fil in _context.Files
select fil;
if (FileID != null)
{
files.Where(x => x.FileID == FileID);
}
if (type != null)
{
files.Where(x => x.FileTypeID == type);
}
if (Status != null)
{
files.Where(x => x.FileStatusID == Status);
}
return files.ToList<File>(开发者_运维知识库);
}
Any mistake i am doing here?
Thanks in advance!
You need to assign the Where back to the IQueryable.... (ie: files = files.where(....
public IList<File> SearchFiles(int? FileID, int? type, int? Status)
{
var files = from fil in _context.Files
select fil;
if (FileID != null)
{
files = files.Where(x => x.FileID == FileID);
}
if (type != null)
{
files = files.Where(x => x.FileTypeID == type);
}
if (Status != null)
{
files = files.Where(x => x.FileStatusID == Status);
}
return files.ToList<File>();
}
精彩评论