当前位置: 首页 > 编程语言 > C#

LINQtoSQLininandnotin分享

时间:2023-04-10 23:09:25 C#

LINQtoSQLininandnotinLINQtoSQL等于notin吗?例如select*fromtablein(...)和select*fromtablenotin(..)在LINQtoSQL中等同于上述语句的是什么?您使用where.Contains()varmyProducts=frompindb.ProductswhereproductList.Contains(p.ProductID)selectp;或者您可以预定义列表:int[]ids={1,2,3};varquery=fromitemincontext.itemswhereids.Contains(item.id)选择项目;对于“不”的情况,只需添加“!‘包含’语句之前的运算符。我对你的问题感到困惑。不是在操作查询中,但您没有在示例查询中指定字段。所以它应该看起来像这样:select*fromtablewherefieldnamein('val1','val2')或select*fromtablewherefieldnamenotin(1,2)LINQtoSQL中那些查询的等效项类似于this:ListvalidValues=newList(){"val1","val2"};varqry=fromitemindataContext.TableNamewherevalidValues.Contains(item.FieldName)选择项目;还有这个:ListvalidValues=newList(){1,2};varqry=fromitemindataContext.TableNamewhere!validValues.Contains(item.FieldName)选择项目;请尝试使用SQL而不是INvarv=fromcsincontext.Sal_Customerjoinsagincontext.Sal_SalesAgreementoncs.CustomerCodeequalssag.CustomerCodewhere!(fromcusincontext.Sal_Customerjoincfcincontext.Sal_CollectionFromCustomersoncus.CustomerCode等于cfc.CustomerCode其中cus.UnitCode==locationCode&&cus.Status==Helper.Active&&cfc.CollectionType==Helper.CollectionTypeDRF选择cus.CustomerCode).Contains(cs.CustomerCode)&&cs.UnitCode==locationCode&&cs.Status==ccustomerStatus&&SqlFunctions.DateDiff("Month",sag.AgreementDate,drfaDate)请尝试使用SQLIN。以上就是C#学习教程:LINQtoSQLinin和notin的全部内容,如果对大家有用,还需要了解更多C#学习教程,希望大家多多关注---语境。Sal_PackageOrItemCapacity.Where(c=>c.ProjectCode==projectCode&&c.Status==Helper.Active&&c.CapacityFor.Contains(isForItemOrPackage)).ToList();本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如有转载请注明出处: