【发布时间】:2020-12-01 12:25:49
【问题描述】:
我有一个customer 表,其中包含firstname、lastname 列和一个三元组索引:
CREATE INDEX ix_customer_search_trgm ON customer USING gin ((firstname || lastname ) gin_trgm_ops);"
我正在尝试使用 C#/EFCore 按名字或姓氏搜索客户,但不知道如何为 firstname || lastname 指定串联表达式
我尝试了以下
-
dbContext.Customers.Where(q => EF.Functions.ILike('firstname || lastname', $"%{searchTerm}%"));这会生成如下查询(注意$1 = 'f'看起来很奇怪)并且与列不匹配
2020-12-01 23:04:52.119 AEDT [38091] LOG: execute <unnamed>: SELECT ...
FROM customer AS c
WHERE $1
2020-12-01 23:04:52.119 AEDT [38091] DETAIL: parameters: $1 = 'f'
-
dbContext.Customers.Where(q => EF.Functions.ILike(q.firstname, $"%{searchTerm}%"));这会生成我期望的那种查询,但显然只过滤表达式中的一列。
2020-12-01 23:02:21.777 AEDT [38034] LOG: execute <unnamed>: SELECT ...
FROM customer AS c
WHERE c.customer ILIKE $1 ESCAPE ''
2020-12-01 23:02:21.777 AEDT [38034] DETAIL: parameters: $1 = '%abc%'
如何使用 EF Core 为上述内容指定串联表达式?
【问题讨论】:
标签: c# postgresql entity-framework npgsql