我正在使用Devart DotConnect For Oracle和EF Core 2.0.1。当我在下面执行代码时,Entity Framework会生成错误的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
答案 0 :(得分:0)
我解决了这个问题。问题实际上是由.HasForeignKey(typeof(ExampleEntity),@&#34; Id&#34;)引起的。我将此行更改为.HasForeignKey(&#34; Id&#34;)并且它有效。我不知道为什么那条线炸毁了查询生成