Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (1 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 7-Aug-20 21:11pm

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.

C#
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,
 
Share this answer
 
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();
C#
ViewBag.Customer=entity.Customers.Where(i=>i.MobileNumber==12321 && i.Nmae=="abc").firstordefault();

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

Hope this helps.
 
Share this answer
 
v2
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
 
Share this answer
 
Dont use x=>x. again after &&, query should be db.student.where(x=>x.roll='1121' && x.name=='NAME')
 
Share this answer
 
Comments
Richard Deeming 10-Aug-20 6:40am    
As already explained in Solution 3, back in 2013.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900