I am trying to insert if statement within Where in a model,
q = from vw_masterview in ctx.vw_MasterViews
where
vw_masterview.LastDate <= toDate &&
vw_masterview.OfficeId == MemberRepository.AllowedOfficeId
AllowedOfficeId could be null, I would like to add if statment
q = from vw_masterview in ctx.vw_MasterViews
where
vw_masterview.LastDate <= toDate &&
***if (MemberRepository.AllowedOfficeId != null)***
vw_masterview.OfficeId == MemberRepository.AllowedOfficeId
Thanks in advance.
You can rewrite your query using the fluent notation and apply an additional
Wherestatement whenAllowedOfficeIdisn’t null:Then you can either run the query or continue to build it up, such as using the
Selectmethod to retrieve specific properties or project into an anonymous type or new class.