Entity Framework 4.0 numeric/decimal bug

Server Error in '/' Application.

Common Language Runtime detected an invalid program.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidProgramException: Common Language Runtime detected an invalid program.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidProgramException: Common Language Runtime detected an invalid program.]
   System.Data.Entity.DynamicProxies.T_UserLoginAccount_BAC9053188C2DB414C3643A0AF5256C5C0F0518E788B9DFF504A5DAC861D9342.set_UserId(Decimal ) +0
   lambda_method(Closure , Shaper ) +318
   System.Data.Common.Internal.Materialization.Shaper.HandleEntityAppendOnly(Func`2 constructEntityDelegate, EntityKey entityKey, EntitySet entitySet) +267
   lambda_method(Closure , Shaper ) +338
   System.Data.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper shaper) +10486357
   System.Data.Common.Internal.Materialization.SimpleEnumerator.MoveNext() +136
   System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +472
   System.Linq.Enumerable.ToList(IEnumerable`1 source) +80
   DataAccess.GetUser(Int32 UserID) +211
   DataAccess.GetUser(Int32 UserID) +122
   caiminjia.Layered.WebUI.Controllers.homeController.Index(String type) +257
   lambda_method(Closure , ControllerBase , Object[] ) +127
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +258
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +39
   System.Web.Mvc.<>c__DisplayClassd.<InvokeActionMethodWithFilters>b__a() +125
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +640
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +312
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +709
   System.Web.Mvc.Controller.ExecuteCore() +162
   System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__4() +58
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +20
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +453
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +371

做项目的时候,出现这个问题,经过baidu,google,发现是Entity Framework 4.0 的一个bug,

数据库: MS SQL Server 2008,

服务器操作系统: Windows Server 2008 R2

IIS版本: IIS 7.5

数据库中表的主键字段类型为: numeric(20,0) identity(1,1)

 解决办法目前我能想到的有两种

    一 .  把主键字段的数据类型改为: int 或 bigint,  不能改为 decimal (经测试 decimal 时,会出现和 numeric 一样的错误)

   二.   把 EF 换掉,用其它 ORM 或 使用 ADO.NET

 

另据消息称,最新版本的 EF4.1 也没有解决这个 bug.

 

以此留念,以防后患.

 

 

 

 

 

 

 


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1

posted @ 2011-05-12 10:45  Own_nothing  阅读(1216)  评论(3编辑  收藏  举报
广州科讯信息科技有限公司