DbContext crashes with PrimitiveType != null error

无人久伴 提交于 2020-01-13 10:29:06

问题


Using Entity Framework Code First, the web application crashes on a call to DbContext with the following error:

Assertion failed

Expression: primitiveType != null

Description: Assertion failed: primitiveType != null

It crashes on the following line of code:

public class MyDb : DbContext {

which is called by:

MyDb _db = new MyDb();

So it seams like calling DbContext generates a fatal error. DbContext is an EF function and I cannot debug inside EntityFramework.dll


回答1:


It's a problem related to older versions of EntityFramework. It happens sometimes when copying a Visual Studio Project to a different machine. This can cause the application to calculate a different ModelHash than the one that is in the database (inside the EdmMetaData table). Solution is to delete the EdmMetaData table and use DbDatabase.SetInitializer<MyContext>( new DropCreateDatabaseIfModelChanges<MyContext>()); to put it back in place, or even better: Upgrade to a newer version of EntityFramework that is not utilizing the EdmMetaData table and ModelHashes.




回答2:


After installing asp.net4.5 I have same error. The Answer for me is to update Entity Framework to new version.

Deleting "EdmMetaData" table didn't resolve the error.




回答3:


I swicth to linq to sql and dint get this error. Dont know what entities is doing to cause this.




回答4:


You need to update your EntityFramework version



来源:https://stackoverflow.com/questions/10430223/dbcontext-crashes-with-primitivetype-null-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!