CLR detected an invalid program with Entity Framework

柔情痞子 提交于 2019-12-08 02:01:15

问题


I am retrieving data from a wordpress database which defines the primary key as decimal and I am using a x64 configuration on the project...

The bit I searched I found out that it is the problem, but I couldn't find a solution.

What do I have to do/download to be able to use decimal as a primary key?

This issue on Microsoft Connect


回答1:


If you're only reading data from the table you can try creating a view that casts the field to an int and then map your entity to the view.

Beyond that, I think you're pretty much out of luck. This is a bug in Entity Framework; either change the field type, switch away from EF, or wait for MS to fix the bug.




回答2:


I had the same problem and I solved it today by putting those two options to false in the DBContext object:

this.ContextOptions.LazyLoadingEnabled = false;

this.ContextOptions.ProxyCreationEnabled = false;

It seems to be a serialization problem with the proxy creation.

I tried first to map my types to Int32 in the EDMX file but this gave me very low performances.




回答3:


Have you tried the Entity Framework 4.1 Release Candidate? The bug was marked as fixed as month or so back.




回答4:


I ran into the same problem, and sad to say: it is still not fixed by Microsoft. I tried EF 4.1 and EF 5.0, but they do not contain any fix for this problem.

The only workaround so far was to change all decimal primary keys to Int64. That, of course, is a change in DB schema, which is not what you wanted. The other option is to use 32 bit environment, that bug is present in 64 bit only.

The comment by PJ (on 11/11/2011 at 11:46 AM ) on https://connect.microsoft.com/VisualStudio/feedback/details/620031/invalidprogramexception-using-entityframework-poco-template-table-w-decimal-primary-key does not sound promising at all, maybe it's not even fixed in .NET 4.5



来源:https://stackoverflow.com/questions/5480972/clr-detected-an-invalid-program-with-entity-framework

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