使用帶代碼的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