MySql to EF在SaveChange時報Null 參考的錯誤

來源:互聯網
上載者:User

標籤:

項目中有使用MySql資料庫,EF做資料層,發現有一張表儲存時始終報錯。報錯資訊如下

System.NullReferenceException: 未將對象引用設定到對象的執行個體。
   在 MySql.Data.Entity.ListFragment.WriteSql(StringBuilder sql)
   在 MySql.Data.Entity.SelectStatement.WriteSql(StringBuilder sql)
   在 MySql.Data.Entity.InsertStatement.WriteSql(StringBuilder sql)
   在 MySql.Data.Entity.SqlFragment.ToString()
   在 MySql.Data.Entity.InsertGenerator.GenerateSQL(DbCommandTree tree)
   在 MySql.Data.MySqlClient.MySqlProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
   在 System.Data.Common.DbProviderServices.CreateCommandDefinition(DbCommandTree commandTree)
   在 System.Data.Common.DbProviderServices.CreateCommand(DbCommandTree commandTree)
   在 System.Data.Mapping.Update.Internal.UpdateTranslator.CreateCommand(DbModificationCommandTree commandTree)
   在 System.Data.Mapping.Update.Internal.DynamicUpdateCommand.CreateCommand(UpdateTranslator translator, Dictionary`2 identifierValues)
   在 System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary`2identifierValues,List`1 generatedValues)
   在 System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
   在 System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)
   在 System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)
   在 System.Data.Entity.Internal.InternalContext.SaveChanges()
   在 System.Data.Entity.Internal.LazyInternalContext.SaveChanges()
   在 System.Data.Entity.DbContext.SaveChanges()

後來在StackOverFlow上得到提示,發現是MySql Connector .Net 6.6.5這個版本的問題,在這個版本中,如果表中的主鍵是自增長的,當該列的類型是TinyInt、UTinyInt、UBigInt時,會出現以上錯誤。但是沒有得到解決方案。

 

不過無需太大驚慌,在之前的版本沒有發現這個問題,然後去官網看了一下,最新的MySql Connector .Net已經是6.9.5,經測試也沒有這個問題。

MySql to EF在SaveChange時報Null 參考的錯誤

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.