实体框架的Where子句中的多个条件在MVC中使用MODEL [英] Multiple condition in Where clause of entity framework Using MODEL in MVC

查看:168
本文介绍了实体框架的Where子句中的多个条件在MVC中使用MODEL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用实体框架从数据库进行数据访问。我想根据两个条件从表中获取数据。例如客户表中用户的mobileNumber和Name。

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



但这不起作用,任何人都可以回答如何检查实体框架的where子句中的多个条件

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

推荐答案

您可以按照下面的示例进行操作。首先,您可以在SQL查询分析器中检查您的给定条件下的任何记录,然后您将尝试实体框架。



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,


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.


直接通过实例访问列后检查第一个条件



(i => i.tablecolumnname ==列名&& i.column == column)在这个你得到

之后,i就是这样你访问表格中的所有列名
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


这篇关于实体框架的Where子句中的多个条件在MVC中使用MODEL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆