I am new to entity framework.
I need to develop a Linq query based on Orders and Customers.
for eg: string firstName can have any of the three values
1) null
2) Joe
3) like %Joe%’
simailary i need to develop for lastname
My current query is like this
using (NorthwindEntities ent = new NorthwindEntities())
{
var UsersList = ent.User.Include("Orders").
Include("OrderDetails").
Include("OrderDetails.Products").
.Where(o => (firstName== null || o.firstName== firstName||o.firstName.Contains(firstName))
&& (LastName== null || o.LastName== LastName ||o.LastName.contains(LastName) )
}
Is my query is correct. Is any other better option to write linq entity query.
Thanks
You can add conditions to a Queryable object. The conditions will build up until the data query is executed.