我在創建IdentityRole
時遇到了這個奇怪的錯誤。 在我的數據庫初始化類我有關於IdentityRole創建日期時間轉換錯誤?
public class DatePickerDbInitializer:CreateDatabaseIfNotExists<DatePickerDbContext>
{
protected override void Seed(DatePickerDbContext context)
{
InitializeDatePickerDbForEf(context);
base.Seed(context);
}
private static void InitializeDatePickerDbForEf(DatePickerDbContext context)
{
var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(context));
var licenseTrial = new License
{
Name = "Trial",
Description = "Works for 14 days"
};
var licenseFull = new License
{
Name = "Full",
Description = "Subscription based"
};
context.Licenses.Add(licenseTrial);
context.Licenses.Add(licenseFull);
var connectionDefault = new Connection
{
Name = "Default"
};
var conncetionSuperOffice = new Connection
{
Name = "SuperOffice"
};
context.Connections.Add(connectionDefault);
context.Connections.Add(conncetionSuperOffice);
roleManager.Create(new IdentityRole("Admin"));
roleManager.Create(new IdentityRole("NonAdmin"));
var user = new ApplicationUser()
{
UserName = "biplov",
Email = "[email protected]",
DateTimeRegistered = DateTime.UtcNow,
IsApproved = true,
LicenseId = licenseFull.Id,
};
var licenseInfo = new UserLicenseInfo
{
LicenseId = licenseFull.Id,
OwnerId = user.Id,
StartDateTime = DateTime.UtcNow
};
context.LicenseInfos.Add(licenseInfo);
var userConnection = new UserConnection()
{
UserId = user.Id,
ConnectionId = connectionDefault.Id
};
context.UserConnections.Add(userConnection);
userManager.AddToRoleAsync(user.Id, "Admin");
}
}
當我第一次InitializeDatePickerDbForEf方法被調用運行程序。 而下面的代碼行roleManager.Create(new IdentityRole("Admin"));
的執行過程中出現了錯誤,說:{"The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.\r\nThe statement has been terminated."}
我怎樣才能得到的日期時間轉換的錯誤創建角色時?錯誤是否受到以前代碼行的影響?我曾與RoleManager曾在之前:(想不會)
的Visual Studio版本:2013 Asp.Net MVC版本:5.1 數據庫:MS-SQL
編輯1 MVC 5,從來沒有得到這種錯誤。不知道爲什麼我得到這個錯誤。
哪個數據庫這裏 –
微軟SQL二手.. – Cybercop
郵政數據庫設計請 –