C#。 NPOCO。错误 : "Incorrect syntax near ' &'. " when trying to join

标签 c# sql sql-server stored-procedures npoco

我有这个存储过程,由 NPOCO 在下一个 linq 查询之后创建:

var componentVarians = _repository.Get().Include(x => x.Component)
                .Where(x => x.IsActive == true &
                            x.ServingTypeId == servingType &
                            x.Component.IsActive == true &          
 x.Component.BotanicalName.ToLower().Contains(value.ToLower())).ToList();


exec sp_executesql N'SELECT [CVD].[Id] as [Id], [CVD].[Name] as [Name], [CVD].[Sku] as [Sku], [CVD].[ServingTypeId] as [ServingTypeId], [CVD].[Price] as [Price], [CVD].[IsActive] as [IsActive], [CD].[Id] as [Component__Id], [CD].[BotanicalName] as [Component__BotanicalName], [CD].[HebrewName] as [Component__HebrewName], [CD].[PinYanName] as [Component__PinYanName], [CD].[IsActive] as [Component__IsActive], [CD].[CreatedDate] as [Component__CreatedDate] FROM [ComponentVariant] [CVD]  
  LEFT JOIN [Component] [CD] ON [CVD].[ComponentId] = [CD].[Id] 
WHERE (((([CVD].[IsActive] = @0) & ([CVD].[ServingTypeId] = @1)) & ([CD].[IsActive] = @2)) & upper(lower([CD].[BotanicalName])) like @3 escape ''\'') ',N'@0 int,@1 int,@2 int,@3 nvarchar(4000)',@0=1,@1=1,@2=1,@3=N'%A%'

执行此存储过程后,出现错误:

Incorrect syntax near '&'

最佳答案

将您的查询更改为 double &&

var componentVarians = _repository.Get().Include(x => x.Component)
    .Where(x => x.IsActive == true &&
                x.ServingTypeId == servingType &&
                x.Component.IsActive == true && 
                x.Component.BotanicalName.ToLower().Contains(value.ToLower())).ToList();

关于C#。 NPOCO。错误 : "Incorrect syntax near ' &'. " when trying to join,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56274103/

相关文章:

c# - 显示来自 Respose.WriteFile()/Response.ContentType 的广告内容

c# - NUnit TestCase - 作为属性参数的数组不符合 CLS

sql - 我如何在一条语句中的 SQL 中执行此操作?

sql - sql server中两个日期之间的月份,其中每个日期在sql server中的开始和结束日期

sql-server - SQL 查询 SELECT FROM [来自另一个表的列的值]

sql-server - 事务复制有什么用?

c# - LINQ to SQL 延迟加载

c# - Generics Fun : Where typeof(List<T>) ! = typeof(List<T>),并使用反射获取泛型方法,带有泛型参数

c++ - 获取 SQLite 结果中的列数

mysql - 优先考虑版本存在的某些行