我正在尝试首先将自动迁移与实体框架和代码一起使用。我向我的班级添加了新属性(团队也是自定义班级):
public virtual Team SecondTeam { get; set; }
我在更新数据库时遇到问题。在我编写命令后,我在控制台中得到了这个:
SQL Server Compact 不支持直接重命名列。要重命名 SQL Server Compact 中的列,您需要重新创建它。
通常正在更新工作(我尝试添加简单的 int 道具并且它只是更新)但如果那是虚拟的我有问题。谁能帮我这个?谢谢
编辑:之后的所有行Update-Database -Verbose
Using NuGet project 'Project'.
Using StartUp project 'Project'.
Target database is: '|DataDirectory|database.sdf' (DataSource: |DataDirectory|database.sdf, Provider: System.Data.SqlServerCe.4.0, Origin: Configuration).
No pending explicit migrations.
Applying automatic migration: 201206130828142_AutomaticMigration.
Direct column renaming is not supported by SQL Server Compact. To rename a column in SQL Server Compact, you will need to recreate it.
Edit2:我要更改数据库的播放器类:
public class Player
{
[Key]
public int PlayerID { get; set; }
[Required]
public string Name { get; set; }
[Required]
public string Surname { get; set; }
public string Nickname { get; set; }
public DateTime Birth { get; set; }
public string PhotoUrl { get; set; }
public string Post { get; set; }
public int TeamID { get; set; }
public virtual Team Team { get; set; }
public int SecondTeamID { get; set; }
public virtual Team SecondTeam { get; set; }
public int UserId { get; set; }
public virtual User User { get; set; }
}
团队班:
public class Team
{
[Key]
public int TeamID { get; set; }
public string Name { get; set; }
public string League { get; set; }
public string Trainings { get; set; }
public string PhotoUrl { get; set; }
public int CoachID { get; set; }
public int AassistantID { get; set; }
public int ManagerID { get; set; }
public virtual ICollection<Player> Players { get; set; }
public bool showPosts { get; set; }
}
这是 EF 生成的 SQL:
CREATE TABLE "Players" (
"PlayerID" int not null identity,
"Name" nvarchar(4000) not null,
"Surname" nvarchar(4000) not null,
"Nickname" nvarchar(4000) null,
"Birth" datetime not null,
"PhotoUrl" nvarchar(4000) null,
"Post" nvarchar(4000) null,
"TeamID" int not null,
"SecondTeamID" int not null,
"UserId" int not null,
"Team_TeamID" int null,
"Team_TeamID1" int null,
"SecondTeam_TeamID" int null,
PRIMARY KEY ("PlayerID")
);
ALTER TABLE "Players" ADD CONSTRAINT "Team_Players" FOREIGN KEY ("Team_TeamID") REFERENCES "Teams"("TeamID");
ALTER TABLE "Players" ADD CONSTRAINT "Player_Team" FOREIGN KEY ("Team_TeamID1") REFERENCES "Teams"("TeamID");
ALTER TABLE "Players" ADD CONSTRAINT "Player_SecondTeam" FOREIGN KEY ("SecondTeam_TeamID") REFERENCES "Teams"("TeamID");
ALTER TABLE "Players" ADD CONSTRAINT "Player_User" FOREIGN KEY ("UserId") REFERENCES "Users"("UserID") ON DELETE CASCADE;