Click here to Skip to main content
13,199,550 members (62,601 online)
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 22-Jan-13 18:12pm
Updated 19-Dec-16 17:53pm
Rate this: bad
 
good
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,
  Permalink  
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: bad
 
good
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.
  Permalink  
v2
Rate this: bad
 
good
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
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web02 | 2.8.171020.1 | Last Updated 19 Dec 2016
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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