日期:2014-05-20  浏览次数:21123 次

关于EF连接MySql的问题,求指导
今晚在用VS2010学习EF连接MySql数据库是,总是报错,错误如下
   System.Data.EntityCommandExecutionException: 执行命令定义时出错。有关详细信息,请参阅内部异常。 
   ---> System.Collections.Generic.KeyNotFoundException: 给定关键字不在字典中。
   在 System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   在 MySql.Data.MySqlClient.CharSetMap.GetCharacterSet(DBVersion version, String CharSetName)
   在 MySql.Data.MySqlClient.MySqlField.SetFieldEncoding()
   在 MySql.Data.MySqlClient.MySqlField.set_CharacterSetIndex(Int32 value)
   在 MySql.Data.MySqlClient.NativeDriver.GetColumnData(MySqlField field)
   在 MySql.Data.MySqlClient.NativeDriver.GetColumnsData(MySqlField[] columns)
   在 MySql.Data.MySqlClient.Driver.GetColumns(Int32 count)
   在 MySql.Data.MySqlClient.ResultSet.LoadColumns(Int32 numCols)
   在 MySql.Data.MySqlClient.ResultSet..ctor(Driver d, Int32 statementId, Int32 numCols)
   在 MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId)
   在 MySql.Data.MySqlClient.MySqlDataReader.NextResult()
   在 MySql.Data.MySqlClient.MySqlDataReader.Close()
   在 MySql.Data.MySqlClient.MySqlCommand.ResetReader()
   在 MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
   在 MySql.Data.Entity.EFMySqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
   在 System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
   在 System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
   --- 内部异常堆栈跟踪的结尾 ---
   在 System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
   在 System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)
   在 System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
   在 System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()


调用方法如下
using (var context = new LsftaobaodmEntities())
                {
                    foreach (var item in context.facktransaction)
                    {
                        resList.Add(new FackOrder()
                        {
                            Uid = item.Uid,
                            QQNumber = item.QQNumber,
                            FakeOrdeDate = item.FakeOrdeDate,
                            FakePrice = item.FackePrice,
                            BigAccount = item.BigAccount,
                            SmallAccount = item.SmallAccount,
                            SCTime = item.SCTime,
                            SCStatus = item.SCStatus,
                            UseAccount = item.UseAccount,
                            Balace = item.Balance
                        });
                    }
                }