没有映射到数据操作中使用的列“CleaningEmployees.Id”的属性

Lum*_*ack 2 c# entity-framework-core .net-core

我正在开发一个 .NET Core c# 项目。我正在使用 Entity Framework Core 连接到数据库。我之前已经创建过它并且它有效。然后我将列的数据类型id从更改uintint,现在我无法重新创建它。

\n

我使用了命令

\n
dotnet ef database update 0\n
Run Code Online (Sandbox Code Playgroud)\n

所以我不必删除该列并重新创建它。

\n

我收到此错误:

\n

在此输入图像描述

\n

由于这不起作用,我尝试将其改回来,但现在也不再起作用了。我也不明白这个错误消息想告诉我什么。

\n

有谁知道是什么问题?

\n

以下是课程:

\n
using 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}\n
Run Code Online (Sandbox Code Playgroud)\n

该类继承自 Employee 类:

\n
using 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}\n
Run Code Online (Sandbox Code Playgroud)\n

而employee类继承自person类:

\n
using 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}\n
Run Code Online (Sandbox Code Playgroud)\n

这是id我之前更改过的属性uintint然后又更改回来的属性int

\n

我不知道它是否与该问题有关,但这是我使用的种子方法:

\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);\n
Run Code Online (Sandbox Code Playgroud)\n

小智 6

对于任何遇到这个问题的人!遇到了同样的问题,因为我直接更新迁移文件忘记更新 [migration_name].Designer.cs 部分文件。

确保设计器文件反映最新的数据库架构和属性。