使用带代码的EF4.1首先创建数据库。尝试使用EF4.1创建数据库时出现奇怪的错误代码优先
我有我的MVC3模型,看起来像这样
public class BusinessContactDetailsModel
{
public int Id { get; set; }
[Display(Name = "Contact Date")]
public DateTime ContactDate { get; set; }
[Range(1, 5)]
[Display(Name = "Outcome Rating")]
public int OutcomeRating { get; set; }
[DataType(DataType.MultilineText)]
public string Comment { get; set; }
public int BusinessId { get; set; }
[Display(Name = "Method of Contact")]
public int FormOfContactId { get; set; }
[Display(Name = "Follow up Date")]
public DateTime FollowUpDate { get; set; }
}
,当我尝试运行在构建过程中的应用程序,它失败。我知道它的FollowUpProperty导致问题,因为它是我刚添加的一个新属性,奇怪的是如果我将属性从DateTime更改为Int,那么它的工作正常。
有没有其他人有这种问题?
我的堆栈跟踪看起来像
[SqlCeException(0X80004005):当转换到日期时间时发生溢出。] System.Data.SqlServerCe.SqlCeCommand.ProcessResults(的Int32小时)125 System.Data .SqlServerCe.SqlCeCommand.ExecuteCommandText(IntPtr的& pCursor,布尔& isBaseTableCursor)631 System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand(的CommandBehavior行为,字符串方法,ResultSetOptions选项)509 System.Data.SqlServerCe.SqlCeCommand.ExecuteNonQuery( )+46 系统.Data.SqlServerCe.SqlCeMultiCommand.ExecuteReader(的CommandBehavior行为)152 System.Data.SqlServerCe.SqlCeMultiCommand.ExecuteDbDataReader(的CommandBehavior行为)36 System.Data.Common.DbCommand.ExecuteReader(的CommandBehavior行为)10 System.Data .Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator翻译,EntityConnection连接,字典
2 identifierValues, List
1个generatedValues)8118684 System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager,IEntityAdapter适配器)267
[UpdateException:更新条目时发生错误。请参阅内部异常的详细信息。] System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager,IEntityAdapter adapter)+389 System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)+163 系统。 Data.Objects.ObjectContext.SaveChanges(SaveOptions选项)+609 System.Data.Entity.Internal.InternalContext.SaveChanges()+326
[DbUpdateException:更新条目时发生错误。有关详细信息,请参阅内部异常。] System.Data.Entity.Internal.InternalContext.SaveChanges()+372 System.Data.Entity.Internal.LazyInternalContext.SaveChanges()+48 System.Data.Entity.DbContext.SaveChanges ()+47 System.Data.Entity.DropCreateDatabaseIfModelChanges 1.InitializeDatabase(TContext context) +502 System.Data.Entity.<>c__DisplayClass2
1.b_ 0(DbContext c)+143 System.Data.Entity.Internal。 <>Ç _DisplayClass5.b__3()59 System.Data.Entity.Internal.InternalContext.PerformInitializationAction(动作动作)101
[DataException:初始化数据库时发生异常。有关详细信息,请参阅InnerException。] System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)+157 System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()+260 System.Data.Entity.Internal。 LazyInternalContext。b__4(InternalContext c)+31 System.Data.Entity.Internal.RetryAction 1.PerformAction(TInput input) +147 System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action
1 action)+276 System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase()+112 System.Data.Entity.Internal.InternalContext。 Initialize()+41 System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)+34 System.Data.Entity.Internal.Linq.InternalSet 1.Initialize() +148 System.Data.Entity.Internal.Linq.InternalSet
1.GetEnumerator()+33 System.Data.Entity。 Infrastructure.DbQuery 1.System.Collections.Generic.IEnumerable<TResult>.GetEnumerator() +91 System.Collections.Generic.List
1..ctor(IEnumerable 1 collection) +315 System.Linq.Enumerable.ToList(IEnumerable
1 source)+58 C:\ Users \ sp \ documents \ visual studio 2010 \ Projects \ MyApplication.CRM \ MyApplication中的MyApplication.CRM.Controllers.BusinessController.Index()。 CRM \ Controllers \ BusinessController.cs:23System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller,Object [] parameters)+17 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext,IDictionary 2 parameters) +208 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary
2个参数)+27 System.Web.Mvc。 <> C_ DisplayClass15.b _12()55 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter滤波器,ActionExecutingContext preContext,函数功能1 continuation) +263 System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +19 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList
1个滤波器,ActionDescriptor actionDescriptor,IDictionary的2 parameters) +191 System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +343 System.Web.Mvc.Controller.ExecuteCore() +116 System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97 System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10 System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37 System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21 System.Web.Mvc.Async.<>c__DisplayClass8
1.b__7(IAsyncResult的)12 System.Web.Mvc.Async.WrappedAsyncResult`1.End()62 System.Web.Mvc。<> c^ _DisplayClasse.b_ d()50 System.Web.Mvc.SecurityUtil.b _0( Action f)+7 System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action)+22 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncR esult)60 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult的结果)9 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()8862381 的System.Web .HttpApplication.ExecuteStep(IExecutionStep step,Boolean & completedSynchronously)+184
事实证明,这是因为DateTime不可为空。我改变它允许空日期,现在它工作正常。 – 2011-06-05 04:04:33