Click here to Skip to main content
11,570,462 members (54,597 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# .NET MVC3 Entities
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
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 at 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

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

  Print Answers RSS


Advertise | Privacy | Mobile
Web04 | 2.8.150624.2 | Last Updated 25 Jan 2013
Copyright © CodeProject, 1999-2015
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