I want query sql where Condition And and Or in one Query in Linq. I try to coding in this below but not work. I want to query where id in CEvaUserEva or EEvaUserEva or OEvaUserEva but status must be 'success' Plese help me.
public ActionResult Get(string id)
{
try
{
var result = (
from pre in context.PreChanges
join cus in context.PreEvaCustomers on pre.DocNumber equals cus.CDocNumber
join env in context.PreEvaEnvis on pre.DocNumber equals env.EDocNumber
join oth in context.PreEvaOthers on pre.DocNumber equals oth.ODocNumber
join sta in context.StatusDocs on pre.DocNumber equals sta.SDocNumber
select new GetAll
{
DocNumber = pre.DocNumber,
Users = pre.Users,
UserId = pre.UserId,
CDocNumber = cus.CDocNumber,
CEvaUserEva = cus.CEvaUserEva,
EDocNumber = env.EDocNumber,
EEvaUserEva = env.EEvaUserEva,
ODocNumber = cus.CDocNumber,
OEvaUserEva = oth.OEvaUserEva,
SDocNumber = sta.SDocNumber,
StatusDoc =sta.StatusDoc
})
.Where((g => g.CEvaUserEva == id || g.EEvaUserEva == id ||
g.OEvaUserEva == id && (g => g.StatusDoc== "Success"));
return Ok(result);
}
catch (Exception ex)
{
return BadRequest(ex.Message "GetC 47");
}
}
CodePudding user response:
You need parenthesis around the or block
.Where(g => (g.CEvaUserEva == id || g.EEvaUserEva == id ||
g.OEvaUserEva == id) && g.StatusDoc == "Success");