-1

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  
Littlefoot
  • 131,892
  • 15
  • 35
  • 57
Derviş Kayımbaşıoğlu
  • 28,492
  • 4
  • 50
  • 72
  • What does it mean, "it generates wrong SQL"? What's wrong with it? (Apart from the fact that enclosing oracle names into double quotes generally **is** a bad idea.) – Littlefoot Jan 18 '18 at 20:45
  • `"product.MhpProducts"."MP_WEST_CORE._DOMAIN._ENTITIES._WEST_LIFE._MHP_PRODUCT"` is totally wrong. – Derviş Kayımbaşıoğlu Jan 18 '18 at 21:03
  • Aha. Yes, it really looks wrong. "product.MhpProducts" seems to be OK, but the rest is garbage. I don't use software you do so excuse my ignorance, but - do you have any influence to code that produces that SELECT statement? I mean, can you debug it? – Littlefoot Jan 18 '18 at 21:08
  • I now suspect that my custom naming conventions may cause this issue (it converts table and column names to higher case), altough I am not sure. I will check it out tomorrow morning. – Derviş Kayımbaşıoğlu Jan 18 '18 at 21:12
  • Good luck, by all means! – Littlefoot Jan 18 '18 at 21:14
  • Please send us a test project for reproducing via https://www.devart.com/company/contactform.html. – Devart Jan 19 '18 at 16:47
  • 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. @Devart – Derviş Kayımbaşıoğlu Jan 25 '18 at 09:15

1 Answers1

0

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

Derviş Kayımbaşıoğlu
  • 28,492
  • 4
  • 50
  • 72