Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# C.NPOCO。错误:“尝试加入时,&.”附近的语法不正确_C#_Sql_Sql Server_Stored Procedures_Npoco - Fatal编程技术网

C# C.NPOCO。错误:“尝试加入时,&.”附近的语法不正确

C# C.NPOCO。错误:“尝试加入时,&.”附近的语法不正确,c#,sql,sql-server,stored-procedures,npoco,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

我有一个存储过程,由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%'
执行此存储过程后,我得到一个错误:

“&”附近的语法不正确


将查询更改为双精度查询&&

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();

将查询更改为双精度查询&&

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();

修改Linq表达式:

var componentVarians = _repository.Get().Include(x => x.Component)
    .Where(x => x.IsActive &&
        x.ServingTypeId == servingType &&
        x.Component.IsActive && 
        x.Component.BotanicalName.ToLower().Contains(value.ToLower())).ToList();
bool类型的属性不使用x.IsActive==true或x.IsActive==false。
如果要在错误时进行筛选,请使用评估!x、 i激活

修改Linq表达式:

var componentVarians = _repository.Get().Include(x => x.Component)
    .Where(x => x.IsActive &&
        x.ServingTypeId == servingType &&
        x.Component.IsActive && 
        x.Component.BotanicalName.ToLower().Contains(value.ToLower())).ToList();
bool类型的属性不使用x.IsActive==true或x.IsActive==false。
如果要在错误时进行筛选,请使用评估!x、 IsActive

在Linq中,其中expresion put&&而不仅仅是一个&。在T-SQL中,@LasseVågsætherKarlsen和In the Linq Where expresion put&&而不仅仅是一个&。在T-SQL中,@LasseVågsætherKarlsen和它如何对linq to objects起作用,但由于这是linq to SQL,因此无法正确解析转换,我理解。布尔操作数的&运算符在C中仍然是一个逻辑运算符,我假设实体框架仍会使用它,在生成的SQL中将其转换为&符号没有意义,但我错了。它适用于linq to对象,但由于这是linq to SQL,因此无法正确解析转换。我理解。布尔操作数的&运算符在C中仍然是一个逻辑运算符,我假设Entity Framework仍会使用它,在生成的SQL中将其转换为&符号是没有意义的,但我错了。