【发布时间】: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