c# - Comparing string columns in MySql for EntityFrameworkCore fails to generate proper SQL -
i using mysql.data.entityframeworkcore version 6.10.1-beta write following linq query:
var data = await _context .assets .where(a => string.compare(a.name, "b", stringcomparison.ordinalignorecase) > 0) .take(2) .tolistasync();
where 'name' property string. in other words, want next 2 database entries have 'name' property greater 'b'.
the code works expected outside when @ generated sql, see following:
select `a`.`f_asset_pk`, `a`.`f_asset_type`, `a`.`f_creation_time`, `a`.`f_id`, `a`.`f_is_soft_deleted`, `a`.`f_last_modified_time`, `a`.`f_library_id`, `a`.`f_name`, `a`.`f_owner_id`, `a`.`f_tenant_id` `accounting`.`t_asset` `a`
as can see limit , clauses not in generated sql. applied in memory causing sub-optimal performances.
if remove 'where' in c#, query generated limit. therefore, try compare strings in query through string.compare(a.name, "b", stringcomparison.ordinalignorecase) > 0
, mysql driver gets confused , fails generate proper sql.
is there syntax use compare strings result in proper sql?
note using microsoft.entityframeworkcore 1.1.0.
answer own question:
use string.compare(a.name, "b") > 0
instead of string.compare(a.name, "b", stringcomparison.ordinalignorecase) > 0
.
Comments
Post a Comment