c# - 42P18: 无法确定参数 $12 的数据类型
问题描述
我正在尝试运行此查询,但它告诉我此错误:
42P18: 无法确定参数 $12 的数据类型
bds.DataSource = (from vendas in conexao.Vendas
join nota in conexao.NotaFiscal on vendas.IdNotaFIscal equals nota.Id
join clientes in conexao.Cliente on vendas.IdCliente equals clientes.Id
where (nota.DataEmissao >= periodoInicial || periodoInicial == null) &&
(nota.DataEmissao <= periodoFinal || periodoFinal == null) &&
(clientes.Id == idCliente || idCliente == null) &&
(nota.NumeroNotaFiscal >= notaInicial || notaInicial == null) &&
(nota.NumeroNotaFiscal <= notaFinal || notaFinal == null) &&
(nota.Modelo == mod || mod == null)
orderby nota.Id descending
select new
{
Id = nota.Id,
ClienteId = clientes.NomeRazao,
Chave = nota.Chave,
DataEmissao = nota.DataEmissao,
Status = nota.Status,
NumeroNota = nota.NumeroNotaFiscal,
Modelo = nota.Modelo,
}).ToList();
错误发生在下面这一行,如果我退出,工作正常,我试图改变,但是我需要这个过滤器。我不明白我做错了什么。
(nota.Modelo == mod || mod == null)
这是我填写变量的方式
string mod = String.Empty;
if(modelo != "TODOS") mod = modelo == "NF-E" ? "55" : modelo== "NFC-e" ? "65" : null;
知道如何解决吗?谢谢你。
解决方案
尝试分离过滤。这样的参数不利于 LINQ 翻译和性能。我希望它能解决你的问题。
var query =
from vendas in conexao.Vendas
join nota in conexao.NotaFiscal on vendas.IdNotaFIscal equals nota.Id
join clientes in conexao.Cliente on vendas.IdCliente equals clientes.Id
select new { vendas, nota, clientes };
if (periodoInicial != null)
query = query.Where(x => x.nota.DataEmissao >= periodoInicial);
if (periodoFinal != null
query = query.Where(x => x.nota.DataEmissao <= periodoFinal);
if (idCliente != null)
query = query.Where(x => x.clientes.Id == idCliente);
if (notaInicial != null)
query = query.Where(x => x.nota.NumeroNotaFiscal >= notaInicial);
if (notaFinal != null)
query = query.Where(x => x.nota.NumeroNotaFiscal <= notaFinal);
if (mod != null)
query = query.Where(x => x.nota.Modelo == mod);
var result =
from q in query
orderby q.nota.Id descending
select new
{
Id = q.nota.Id,
ClienteId = q.clientes.NomeRazao,
Chave = q.nota.Chave,
DataEmissao = q.nota.DataEmissao,
Status = q.nota.Status,
NumeroNota = q.nota.NumeroNotaFiscal,
Modelo = q.nota.Modelo,
};
bds.DataSource = result.ToList();
推荐阅读
- dataframe - 查找数据框中同一列的另一个行字符串中包含的行的字符串并将它们隔离
- javascript - Javascript 包装函数和 this 关键字
- google-cloud-platform - 是什么不断访问我的实例上的 Google Cloud 元数据
- php - 在 PHP 数组中显示最大值
- sql - 如何从 SQL 中的地址字段解析 apt no
- azure-devops - 没有权限列出秘密的 Helm 部署
- python - 如何使用 python 而不是 java 编写我的世界 CLIENT/mod?
- asp.net-mvc - 由于我为 Identity 添加了自定义元素,因此未发布视图
- python - 如何将dict列表转换为两个列表?
- logging - Kusto 自定义排序顺序?