I am using Devart DotConnect For Oracle with EF Core 2.0.1. When I execute code below Entity Framework generates wrong SQL. I am considering this as a bug, however I am not sure whether I am the one who is making mistake or not. And also, I need a workaround to be able to solve this issue.
public virtual async Task<TEntity> GetByIdAsync(object[] keyValues,
List<Expression<Func<TEntity, object>>> includes,
CancellationToken cancellationToken = default(CancellationToken))
{
Task<TEntity> model = null;
foreach (var include in includes)
{
await DbSet.Include(include).LoadAsync(cancellationToken);
model = DbSet.FindAsync(keyValues, cancellationToken);
}
if (model == null)
model = DbSet.FindAsync(keyValues, cancellationToken);
return await model;
}
Following code generates The SQL below
SELECT
"product.MhpProducts".mp_mhp_id,
"product.MhpProducts".mp_product_id,
"product.MhpProducts".mp_g_order,
"product.MhpProducts".g_end_date,
"product.MhpProducts".g_insert_by,
"product.MhpProducts".g_insert_date,
"product.MhpProducts".g_is_deleted,
"product.MhpProducts".g_start_date,
"product.MhpProducts"."mp_west_core._domain._entities._west_life._mhp_product"
FROM mhp_product "product.MhpProducts"
inner join (SELECT "product0".tp_id
FROM tree_product "product0") "t"
ON "product.MhpProducts".mp_product_id = "t".tp_id
ORDER BY "t".tp_id
I solved the problem. the problem was actually caused by .HasForeignKey(typeof(ExampleEntity), @"Id"). I changed this line as .HasForeignKey("Id") and it worked. I dont know why that line blowed up query generation