FreeSql icon indicating copy to clipboard operation
FreeSql copied to clipboard

DbFirst.GetTablesByDatabase()方法出错

Open weidea2020 opened this issue 4 years ago • 3 comments

问题描述及重现步骤:

调用DbFirst.GetTablesByDatabase([库名])获取“表、列详情、主键、唯一键、索引、外键、备注”时,抛出“The given key 'Id' was not present in the dictionary. ”错误。

当访问的数据库的表主键字段为id时,则抛出此错误。 如果访问的数据库的表主键不为id时,则正常返回所有表和表结构信息。

数据库的具体版本

mysql 5

安装的包

FreeSql 2.5.200

.net framework/. net core? 及具体版本

.Net Core 5

weidea2020 avatar Oct 03 '21 17:10 weidea2020

如何重现你的问题,是哪个表 或view导致的 。发下数据库?

luoyunchong avatar Oct 04 '21 06:10 luoyunchong

我今天尝试了一下,将之前出现“The given key 'Id' was not present in the dictionary. ”错误的数据库的结构的数据同步到同一服务器另外数据库中,对其进行访问,没有出现错误,正常运行了,那么可以排除是数据结构的问题了,看来即使给出数据库也没什么用了,不知道还有什么其它可能性。

以下是代码捕获的异常信息,希望有帮助 class_name:'System.ThrowHelper', method_name:'ThrowKeyNotFoundException', exception_name:'The given key 'Id' was not present in the dictionary.', exception_msg:'The given key 'Id' was not present in the dictionary.', exception_source:'System.Private.CoreLib', stack_trace:' at System.Collections.Generic.Dictionary`2.get_Item(TKey key) at FreeSql.MySql.MySqlDbFirst.GetTables(String[] database, String tablename, Boolean ignoreCase) at FreeSql.MySql.MySqlDbFirst.GetTablesByDatabase(String[] database)',

weidea2020 avatar Oct 04 '21 16:10 weidea2020

应该是数据库的设置区分了大小写导致的

2881099 avatar Dec 27 '21 14:12 2881099