当我尝试查询数据库中的数据时,我想使用linq在Entity Framework Core中遇到问题,并且如果要提供的值为空,我想返回值,如果为空,并且基本上使用了值过滤器,则基本上返回所有数据>
下面是显示LIKE语句的SQL
ALTER PROCEDURE [dbo].[Pokayokes]
@Action VARCHAR(10)
,@ID_Registo INT = NULL
,@DataInicio VARCHAR(50) = NULL
,@DataFim VARCHAR(50) = NULL
,@Referencia VARCHAR(MAX) = NULL
,@Procura VARCHAR(MAX) = NULL
,@CodigoOperador VARCHAR(MAX) = NULL
AS
BEGIN
SET NOCOUNT ON;
--SELECT
IF @Action = 'PROCURAR'
BEGIN
SELECT
reg.ID_Antierros,
pk.Maquina,
pk.Designacao,
pk.Objectivo,
pk.NumeroPokayoke,
reg.Estado,
re.Data,
re.Referencia,
re.Turno,
re.Operador
FROM RegistoAntiErros reg
join Registo re on reg.ID_Registo=re.ID_Registo
join Pokayoke pk on reg.ID_Pokayoke=pk.ID_Pokayoke
WHERE re.Data BETWEEN @DataInicio AND @DataFim AND re.Referencia LIKE '%' + @Referencia + '%' AND re.Operador LIKE '%' + @CodigoOperador + '%'
order by ID_Antierros asc
END
END
我正在尝试使用linq做类似的事情
PokayokesRegistos = _context.PokayokesRegistos
.Where(pr =>
EF.Functions.Like(pr.Registo.Referencia.Nome, "%" + PokayokeRegistoViewModel.Referencia + "%") &&
pr.Registo.DataInicioTurno >= PokayokeRegistoViewModel.DataInicio && pr.Registo.DataInicioTurno <= PokayokeRegistoViewModel.DataFim)
.OrderByDescending(pr => pr.Id)
.ToList();
但这不起作用吗? Referencia仍然没有记录