I have started testing entity framework core, to replace Ado.Net (running on Framework 4.x), using:
- <TargetFramework>net6.0</TargetFramework>
Server Versión: WI-V2.5.9.27139 Firebird 2.5 (Old Fb database with no Charset)
Trying with these changes in optionBuilder.
This is an example using a simple web Api. Not a real production environment
This line belongs to program.cs file
builder.Services.AddDbContext<ApplicationDbContext>(opt => opt.UseFirebird("name=DefaultConnection",
p => p.WithExplicitStringLiteralTypes(false)
.WithExplicitParameterTypes(true)));
case 1
var pacientes = await _context.MAESTRO_PACIENTES
.Where(x => x.NOMBRE2.StartsWith(nombre))
.OrderBy(o => o.NOMBRE2)
.Take(10)
.ToListAsync();
Sql syntax
Select
"m"."CODIGO",
"m"."NOMBRE2",
...all the other fields...
FROM
"MAESTRO_PACIENTES" AS "m"
WHERE
(CAST('DE LA FUENTE DIEGO' AS VARCHAR(8191)) = _UTF8 '')
OR (
(
(
UPPER("m"."NOMBRE") LIKE CAST('DE LA FUENTE DIEGO' AS VARCHAR(8191)) || _UTF8 '%'
)
AND (
LEFT(
UPPER("m"."NOMBRE"),
CHAR_LENGTH(CAST('DE LA FUENTE DIEGO' AS VARCHAR(8191)))
) = CAST('DE LA FUENTE DIEGO' AS VARCHAR(8191))
)
)
OR (CAST('DE LA FUENTE DIEGO' AS VARCHAR(8191)) = _UTF8 '')
)
Plan
--------------------------------------------------------------------------------
PLAN (m NATURAL)
Reads from disk to cache = 30.640
Writes from cache to disk = 0
Fetches from cache = 3.599.077
****************************************************************************
Case 2
var pacientes = await _context.MAESTRO_PACIENTES
.Where(x => x.NOMBRE2.CompareTo(nombre) >= 0)
.OrderBy(o => o.NOMBRE2)
.Take(10)
.ToListAsync();
Sql syntax
Select
"m"."CODIGO",
"m"."NOMBRE2",
...all the other fields...
FROM
"MAESTRO_PACIENTES" AS "m"
WHERE
"m"."NOMBRE2" >= CAST('DE LA FUENTE DIEGO' AS VARCHAR(8191))
ORDER BY
"m"."NOMBRE2"
Plan
--------------------------------------------------------------------------------
PLAN (m ORDER MAESTRO_PACIENTES_IDX15 INDEX (MAESTRO_PACIENTES_IDX15))
Reads from disk to cache = 2.347
Writes from cache to disk = 0
Fetches from cache = 2.740
I would like to allow using "StartsWith". It is more understandable than the command
I tried to add some options to avoid casting. But I has no effect.
I tried to create a new field "NOMBRE3" with UTF8 charset. No changes