Click here to Skip to main content
14,428,366 members
Rate this:
Please Sign up or sign in to vote.
See more:
i am using entity framework for data access from database. I want to fetch data from a table on the basis of two condition. e.g. "mobileNumber" and "Name" of user in a "Customer" table.
ViewBag.Customer=entity.Customers.Where(i=>i.MobileNumber==12321 && i=>i.Nmae=="abc").firstordefault();

But this is Not working, Can anybody answer how to check multiple condition in where clause of entity framework
Posted
Updated 19-Dec-16 18:53pm
Rate this:
Please Sign up or sign in to vote.

Solution 1

You can follow the bellow example. And Firstly, you can check any record is available with your given condition in SQL Query analyzer and then you will try entity framework.

var repo = new Repositories.Repository<listing>();
            var listings = repo.GetTable().Where(l => l.IsDeleted == false && l.IDListingStatus == 2 && (l.IDListingType == 1 || l.IDListingType == 2 || l.IDListingType == 3));</listing>


Thanks,
   
Comments
Member 9583779 23-Jan-13 6:47am
   
entity is object of my entity framework class.
Model.MyProject entity=new Model.Myproject();

and "Customer" is class build in this entity. from which i want to fetch data on the basis of Multiple condition.

ViewBag.CustomerList=entity.Customers.Where(i=>i.MobileNumber==12321 && i=>i.Nmae=="abc").firstordefault();
Rate this:
Please Sign up or sign in to vote.

Solution 3

ViewBag.Customer=entity.Customers.Where(i=>i.MobileNumber==12321 && i.Nmae=="abc").firstordefault();

Don't need to use again
i=>i.Nmae=="abc"

Hope this helps.
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 4

just check first condition after directly you access the columns by instance

(i=>i.tablecolumnname==column name && i.column==column) in this you get
after "i" is instance by this you access all column names in table
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100