【问题标题】:DbSet Include Generates Incorrect SQL (Devart DotConnect Oracle)DbSet Include 生成不正确的 SQL (Devart DotConnect Oracle)
【发布时间】:2018-01-18 18:40:14
【问题描述】:

我正在使用带 EF Core 2.0.1 的 Devart DotConnect For Oracle。当我在实体框架下执行代码时会生成错误的 SQL。我认为这是一个错误,但我不确定我是否是犯错的人。而且,我需要一个解决方法来解决这个问题。

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;
}

以下代码生成下面的SQL

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  

【问题讨论】:

  • “生成错误的 SQL”是什么意思?它出什么问题了? (除了将 oracle 名称括在双引号中的事实之外,通常 是个坏主意。)
  • "product.MhpProducts"."MP_WEST_CORE._DOMAIN._ENTITIES._WEST_LIFE._MHP_PRODUCT" 完全错误。
  • 啊哈。是的,看起来确实不对。 “product.MhpProducts”似乎还可以,但其余的都是垃圾。我不使用您这样做的软件,请原谅我的无知,但是 - 您对生成该 SELECT 语句的代码有任何影响吗?我的意思是,你能调试一下吗?
  • 我现在怀疑我的自定义命名约定可能会导致这个问题(它将表名和列名转换为大写),尽管我不确定。我明天早上去看看。
  • 祝你好运!

标签: oracle entity-framework entity-framework-core devart dotconnect


【解决方案1】:

我解决了这个问题。问题实际上是由 .HasForeignKey(typeof(ExampleEntity), @"Id") 引起的。我将此行更改为 .HasForeignKey("Id") 并且它有效。我不知道为什么那条线会破坏查询生成

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-23
    • 2011-08-06
    • 2017-03-22
    • 1970-01-01
    • 2010-12-19
    • 1970-01-01
    相关资源
    最近更新 更多