Lum*_*ack 2 c# entity-framework-core .net-core
我正在开发一个 .NET Core c# 项目。我正在使用 Entity Framework Core 连接到数据库。我之前已经创建过它并且它有效。然后我将列的数据类型id从更改uint为int,现在我无法重新创建它。
我使用了命令
\ndotnet ef database update 0\nRun Code Online (Sandbox Code Playgroud)\n所以我不必删除该列并重新创建它。
\n我收到此错误:
\n\n由于这不起作用,我尝试将其改回来,但现在也不再起作用了。我也不明白这个错误消息想告诉我什么。
\n有谁知道是什么问题?
\n以下是课程:
\nusing System;\n\nnamespace CarRental.Classes\n{\n public class CleaningEmployee : Employee\n {\n public CleaningEmployee(string firstName, string lastName, string emailAddress, string street, uint number, string town, DateTime birthday, string phone, string phoneMobile, bool isAvailable) : base(firstName, lastName, emailAddress, street, number, town, birthday, phone, phoneMobile, isAvailable)\n {\n }\n\n public CleaningEmployee()\n {\n }\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n该类继承自 Employee 类:
\nusing System;\n\nnamespace CarRental.Classes\n{\n public class Employee : Person\n {\n public Employee(string firstName, string lastName, string emailAddress, string street, uint number, string town, DateTime birthday, string phone, string phoneMobile, bool isAvailable) : base(firstName, lastName, emailAddress, street, number, town, birthday, phone, phoneMobile)\n {\n IsAvailable = isAvailable;\n }\n\n public Employee()\n {\n }\n\n public bool IsAvailable { get; set; }\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n而employee类继承自person类:
\nusing System;\n\nnamespace CarRental.Classes\n{\n public abstract class Person\n {\n protected Person()\n {\n }\n\n protected Person(string firstName, string lastName, string emailAddress, string street, uint number, string town, DateTime birthday, string phone, string phoneMobile)\n {\n FirstName = firstName;\n LastName = lastName;\n EmailAddress = emailAddress;\n Street = street;\n Number = number;\n Town = town;\n Birthday = birthday;\n Phone = phone;\n PhoneMobile = phoneMobile;\n }\n\n public uint Id { get; set; }\n public string FirstName { get; set; }\n public string LastName { get; set; }\n public string EmailAddress { get; set; }\n public string Street { get; set; }\n public uint Number { get; set; }\n public string Town { get; set; }\n public DateTime Birthday { get; set; }\n public string Phone { get; set; }\n public string PhoneMobile { get; set; }\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n这是id我之前更改过的属性uint,int然后又更改回来的属性int。
我不知道它是否与该问题有关,但这是我使用的种子方法:
\n// Creating cleaningEmployee dummy data\nCleaningEmployee cleaningEmployee1 = new CleaningEmployee("Peter", "Hueber", "peter.huerber@carrental.ch",\n "hueberstrasse", 3, "Zug", new DateTime(2000, 3, 12), "341 324 234 23 12", "234 423 243 43 43", true);\n cleaningEmployee1.Id = 1;\n \nCleaningEmployee cleaningEmployee2 = new CleaningEmployee("Samuel", "M\xc3\xbcller", "samuel.m\xc3\xbcller@carrental.ch",\n "m\xc3\xbcllerstrasse", 3, "Zug", new DateTime(2001, 4, 12), "341 234 234 43 12", "234 234 243 54 43", true);\n cleaningEmployee2.Id = 2;\n \nmodelBuilder.Entity<CleaningEmployee>().HasData(cleaningEmployee1, cleaningEmployee2);\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
3899 次 |
| 最近记录: |