gpt4 book ai didi

entity-framework - EF Core Include 方法不起作用

转载 作者:行者123 更新时间:2023-12-04 07:25:37 24 4
gpt4 key购买 nike

我最近更新到了 asp.net core 2.0。由于使用 Include Method 升级我的所有 Linq 查询都失败了,因此它没有正确转换为 SQL。

例如这个:

var entities = helpTopicRepository.Entities.Include(x => x.HelpArticles).FirstOrDefault(t => topicIds.Any(a => a == t.Id));

翻译成:
SELECT x.HelpArticles.ART_ID, 
x.HelpArticles.AVAILABLE,
x.HelpArticles.CONTENT,
x.HelpArticles.DISPLAYORDER,
x.HelpArticles.HELPFULNO,
x.HelpArticles.HELPFULYES,
x.HelpArticles.KEYWORDS,
x.HelpArticles.TITLE,
x.HelpArticles.TOPICID
FROM HELPARTICLE x.HelpArticles

这导致以下错误:

Devart.Data.Oracle.OracleException (0x80004005): ORA-00933: SQL

command not properly ended at Devart.Data.Oracle.ay.b() at Devart.Data.Oracle.am.f() at Devart.Data.Oracle.am.e() at Devart.Data.Oracle.c5.a(am A_0, Int32 A_1) at Devart.Data.Oracle.c5.a(Int32 A_0, bg A_1) at Devart.Data.Oracle.OracleCommand.InternalExecute(CommandBehavior behavior, IDisposable disposable, Int32 startRecord, Int32 maxRecords, Boolean nonQuery) at Devart.Common.DbCommandBase.ExecuteDbDataReader(CommandBehavior behavior, Boolean nonQuery) at Devart.Data.Oracle.Entity.ai.a(CommandBehavior A_0) at Devart.Common.Entity.cj.d(CommandBehavior A_0) at Devart.Data.Oracle.Entity.ai.b(CommandBehavior A_0) at System.Data.Common.DbCommand.ExecuteReader() at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary2
parameterValues) at
Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteReader(IRelationalConnection
connection, IReadOnlyDictionary
2 parameterValues) at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable1.Enumerator.BufferlessMoveNext(Boolean
buffer) at
Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable
1.Enumerator.MoveNext() at Microsoft.EntityFrameworkCore.Query.Internal.QueryBuffer.IncludeCollection(Int32 includeId, INavigation navigation, INavigation inverseNavigation, IEntityType targetEntityType, IClrCollectionAccessor clrCollectionAccessor, IClrPropertySetter inverseClrPropertySetter, Boolean tracking, Object entity, Func1 relatedEntitiesFactory) at
lambda_method(Closure , QueryContext , Client , Object[] ) at
Microsoft.EntityFrameworkCore.Query.Internal.IncludeCompiler._Include[TEntity](QueryContext
queryContext, TEntity entity, Object[] included, Action
3 fixup) at lambda_method(Closure , Client ) at System.Linq.Enumerable.SelectEnumerableIterator2.MoveNext() at
System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable
1 source) at lambda_method(Closure , QueryContext ) at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass17_0`1.b__0(QueryContext qc) ORA-00933: SQL command not properly ended



我正在使用 Devart dotconnect 连接到 Oracle 数据库。

最佳答案

是因为你的说法:

var entities = helpTopicRepository.Entities.Include(x => x.HelpArticles).FirstOrDefault(t => topicIds.Any(a => a == t.Id));

假设 topicIds是一个列表,这里有一个修复:
var entities = helpTopicRepository.Entities
.Include(x => x.HelpArticles)
.Where(t => topicIds.Contains(t.Id))
.FirstOrDefault();

关于entity-framework - EF Core Include 方法不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47105670/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com