首页 > 解决方案 > 基本查询的 LinqPad 异常:已添加具有相同键的项目

问题描述

我正在使用 LinqPad 连接到 Oracle DB,并且在大多数情况下,它工作正常,但对于某些表,我不断收到错误消息:

ArgumentException:已添加具有相同键的项目

我非常了解字典中不同键的概念;我不明白这里是如何违反这一要求的。

例如,我可以从 LinqPad以 SQL的形式运行以下命令,而不会出现任何问题:

Select * from table_name where rownum < 10

..但是如果我尝试将其作为 C# Expression运行,则会出现上述错误。

TableNames.Take(10);

需要明确的是:OtherTables.Take(10);适用于许多其他表;上述错误仅发生在其中的一个子集上。

初步理论

关于如何解决和避免此错误以及能够使用 Linq 访问表格内容的任何想法?


更新:根据要求,来自 LinqPad 的堆栈跟踪。

至于其他评论:正如我之前提到的,我了解根本原因(重复的键值),但不了解它的来源。该表达式SomeTable.Take(10);本质上是整个查询,只是具有不同的表名。

ved System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
ved System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
ved System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
ved System.Linq.Enumerable.ToDictionary[TSource,TKey](IEnumerable`1 source, Func`2 keySelector)
ved IQToolkit.Data.Mapping.AttributeMapping.AttributeMappingEntity..ctor(Type elementType, String tableId, Type entityType, IEnumerable`1 attrs, IEnumerable`1 mappingMembers)
ved IQToolkit.Data.Mapping.AttributeMapping.CreateEntity(Type elementType, String tableId, Type entityType)
ved IQToolkit.Data.Mapping.AttributeMapping.GetEntity(Type elementType, String tableId, Type entityType)
ved IQToolkit.Data.Mapping.AttributeMapping.GetEntity(Type type, String tableId)
ved IQToolkit.Data.EntitySession.GetTable(Type elementType, String tableId)
ved IQToolkit.Data.EntitySession.GetTable[T](String tableId)
ved IQDriver.IQContextBase.GetTable[T](String name)
ved LINQPad.User.TypedDataContext.get_Phases()
ved UserQuery.RunUserAuthoredQuery() i C:\Users\MyUserName\AppData\Local\Temp\LINQPad5\_jpjdzkge\query_gktujz.cs:linje 36
ved LINQPad.ExecutionModel.ClrQueryRunner.Run()
ved LINQPad.ExecutionModel.Server.RunQuery(QueryRunner runner)

标签: c#sqloraclelinqlinqpad

解决方案


推荐阅读