ef6 拼接where查询条件
Expression<Func<RecipeInfo, bool>> expression = t => true;
expression = expression.And(p => p.IsEfjective==0);
switch (type)
{
case 0:
expression = expression.And(p => p.FilePath.Contains(value));
//queru.Where(p => p.FilePath.Contains(value)) ;
break;
case 1:
expression = expression.And(p => p.Id == Convert.ToInt64(value));
break;
case 2:
expression = expression.And(p => p.DeviceId == Convert.ToInt64(value));
break;
case 3:
expression = expression.And(p => p.LayerId == Convert.ToInt64(value));
break;
case 100:
expression = expression.And(p => true);
break;
}
if (UnitId != 0)
{
expression = expression.And(p => p.UnitId == UnitId);
}
//List
` RecipeInfoListEntity RecipeInfoListEntityList = new RecipeInfoListEntity();
var db = this.BaseRepository().DB.dbContext;
var RecipeInfoDB = db.Set
var RecipeInfoBaseDB = db.Set
var LayerDB = db.Set
var DeviceDB = db.Set
var UserDB = db.Set
var UserDB2 = db.Set
var UserDB3 = db.Set
var queru = from a in RecipeInfoDB
join b in LayerDB on a.LayerId equals b.Id into temp1
from tableTemp1 in temp1.DefaultIfEmpty()
join c in DeviceDB on a.DeviceId equals c.Id into temp2
from tableTemp2 in temp2.DefaultIfEmpty()
join e in UserDB on a.BaseCreatorId equals e.Id into temp3
from tableTemp3 in temp3.DefaultIfEmpty()
join f in UserDB2 on a.BaseModifierId equals f.Id into temp4
from tableTemp4 in temp4.DefaultIfEmpty()
join g in UserDB3 on a.UnitId equals g.Id into temp5
from tableTemp5 in temp5.DefaultIfEmpty()
join h in RecipeInfoBaseDB on a.Id equals h.RecipeInfoId into temp6
from tableTemp6 in temp6.DefaultIfEmpty()
where IsEfjective != 2 ? a.IsEfjective == IsEfjective : true
where UnitId != 0 ? a.UnitId == UnitId : true
where WisType != -1 ? a.ModuleType == WisType : true
where type == 0 ? a.FilePath.Contains(value) : true
where type == 1 ? a.Id == Convert.ToInt64(value) : true
where type == 2 ? a.DeviceId == Convert.ToInt64(value) : true
where type == 3 ? a.LayerId == Convert.ToInt64(value) : true
where type == 4 ? a.GrounpId == Convert.ToInt64(value) : true
where type == 5 ? (tableTemp6.BareMode == Convert.ToInt32(bareMode) && a.FilePath.Contains(value)) : true
where seachText != "" ? a.Name.Contains(seachText) : true
orderby a.BaseCreateTime descending
select new RecipeInfoListEntity
{
Id = a.Id.Value,
recipeName = a.Name,
Name = a.Name,
BaseModifierId = a.BaseModifierId,
BaseModifyTime = a.BaseModifyTime,
BaseCreatorId = a.BaseCreatorId,
BaseCreateTime = a.BaseCreateTime,
deviceName = tableTemp2.Name,
deviceID = a.DeviceId.Value.ToString(),
TechniqueName = tableTemp1.TechniqueName,
TechniqueId = a.LayerId.Value.ToString(),
Tag = a.Tag,
Comment = a.Comment,
InspectionMode = a.InspectionMode.Value.ToString(),
FilePath = a.FilePath,
Image = a.Image,
Revision = a.Revision,
Executable = a.Executable,
ModuleType = a.ModuleType.Value,
//UnitName = a.UnitName,
UnitId = a.UnitId,
UnitName = tableTemp5.Equipment,
WaferSize = a.WaferSize.Value.ToString(),
BaseCreatorName = tableTemp3.Name,
BaseModifierName = tableTemp4.Name,
IndexNumber = tableTemp1.IndexNumber,
Isupload = a.Isupload,
GrounpId = a.GrounpId.Value,
ImageMD5 = a.ImageMD5,
IsUsing = a.IsUsing
};
var joinfdatabase = await queru.ToListAsync();
return joinfdatabase as List<RecipeInfoListEntity>;`