I m building an mvc application, using EF code first. I m right at begning. here is code which is concerned with my problem
Advertisement Model
[Key]
public virtual int ID { get; set; }
public virtual int OwnerID { get; set; }
public virtual int Cycles { get; set; }
public virtual int Tier { get; set; }
public virtual decimal Cost { get; set; }
public string Name { get; set; }
public virtual string FileName { get; set; }
public virtual string Path { get; set; }
public virtual List<AdDisplayTime> DispalyTime { get; set; }
public virtual DateTime CreateDate { get; set; }
public virtual DateTime ValidFrom { get; set; }
public virtual DateTime ValidTill { get; set; }
public virtual DateTime UpdateDate { get; set; }
public virtual int UpdatedBy { get; set; }
public virtual bool FullScreen { get; set; }
public virtual bool IsAdminAd { get; set; }
public virtual int Status { get; set; }AdDisplayTimes Model
[Key]
public virtual int ID { get; set; }
public virtual int AdID { get; set; }
public virtual string DisplayTime { get; set; }
Status Model
[Key]
public virtual int ID { get; set; }
public virtual string Name { get; set; }
Here is seed method in my migrations class
var adDisplayTimes = new List<AdDisplayTime>
{
new AdDisplayTime{AdID = 1,DisplayTime = "10:30"},
new AdDisplayTime{AdID = 1,DisplayTime = "10:40"},
new AdDisplayTime{AdID = 1,DisplayTime = "10:50"},
new AdDisplayTime{AdID = 1,DisplayTime = "11:00"}
};
context.Advertisements.AddOrUpdate(a => a.Name,
new Advertisement
{
Name = "Fisrt Ad",
OwnerID = 1,
Cycles = 125,
Cost = (decimal)234.45,
FileName = "test.jpg",
Tier = 1,
Path = "~/UploadedImages/Pending/test.jpg",
DispalyTime = adDisplayTimes,
CreateDate = DateTime.Now,
ValidFrom = DateTime.Now,
ValidTill = DateTime.Now.AddMonths(1),
FullScreen = true,
IsAdminAd = false,
Status = 1
}
);
context.AdDisplayTimes.AddOrUpdate(ad=>ad.AdID,
new AdDisplayTime { AdID = 1, DisplayTime = "10:30" },
new AdDisplayTime { AdID = 1, DisplayTime = "10:40" },
new AdDisplayTime { AdID = 1, DisplayTime = "10:50" },
new AdDisplayTime { AdID = 1, DisplayTime = "11:00" }
);
context.Statuses.AddOrUpdate(s=>s.Name,
new Status{Name = "Pending"},
new Status{Name = "Approved"},
new Status{Name = "Edited"},
new Status{Name = "Activated"},
new Status{Name = "DeActivated"}
);When i run command "update-database" in package manager in Visual studio I get this
update-database Specify the '-Verbose' flag to view the SQL statements being applied to the target database. No pending code-based migrations. Running Seed method. System.Data.Entity.Infrastructure.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.UpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.SqlClient.SqlException: The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value. The statement has been terminated. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() at System.Data.SqlClient.SqlDataReader.get_MetaData() at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary`2 identifierValues, List`1 generatedValues) at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter) --- End of inner exception stack trace --- at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter) at System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache) at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options) at System.Data.Entity.Internal.InternalContext.SaveChanges() --- End of inner exception stack trace --- at System.Data.Entity.Internal.InternalContext.SaveChanges() at System.Data.Entity.Internal.LazyInternalContext.SaveChanges() at System.Data.Entity.DbContext.SaveChanges() at System.Data.Entity.Migrations.DbMigrator.SeedDatabase() at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.SeedDatabase() at System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId) at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId) at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration) at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration) at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.RunCore() at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run() An error occurred while updating the entries. See the inner exception for details.
Please help me on this