我是新来的。我正在使用Core项目ASP.NET Web应用程序(.NET Core)开发一个解决方案。
它生成初始平滑迁移:使用表,键和索引在 PostgreSQL 中创建的数据库。他正确地添加了种子。
我正在使用Code First选项开展项目。当您运行命令以添加迁移时,将使用Up和Down方法中的代码生成文件,但不会生成更改属性名称的语法。
我一方面尝试创建注释,另一方面尝试更改属性名称,后一种迁移运行Up和Down方法生成为空。
原班级:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace ContosoUniversity.Models
{
public class Estudiante
{
public int ID { get; set; }
public string Apellido { get; set; }
public string PrimerNombre { get; set; }
public DateTime FechaInscripcion { get; set; }
public virtual ICollection<Inscripcion> Inscripciones { get; set; }
}
}
修改后的课程:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace ContosoUniversity.Models
{
public class Estudiante
{
public int ID { get; set; }
[StringLength(50)]
public string Apellido { get; set; }
[StringLength(50, ErrorMessage = "First name cannot be longer than 50 characters.")]
[Column("nombre")]
public string PrimerNombre { get; set; }
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime FechaInscripcion { get; set; }
public virtual ICollection<Inscripcion> Inscripciones { get; set; }
}
}
我运行 dotnet ef迁移添加FormatoEstudiante 和 dotnet ef update datababse 。迁移的结果是:
using Microsoft.EntityFrameworkCore.Migrations;
namespace ContosoUniversity.Migrations
{
public partial class FormatoEstudiante : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "primernombre",
schema: "public",
table: "estudiante",
maxLength: 50,
nullable: true);
migrationBuilder.AlterColumn<string>(
name: "apellido",
schema: "public",
table: "estudiante",
maxLength: 50,
nullable: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "primernombre",
schema: "public",
table: "estudiante",
nullable: true);
migrationBuilder.AlterColumn<string>(
name: "apellido",
schema: "public",
table: "estudiante",
nullable: true);
}
}
}
Project.json:
{
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
},
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
"Microsoft.EntityFrameworkCore": "1.0.0",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
"Microsoft.EntityFrameworkCore.Design": "1.0.0-preview2-final",
"Npgsql": "3.1.7",
"Npgsql.EntityFrameworkCore.PostgreSQL": "1.0.1"},
"tools": {
"BundlerMinifier.Core": "2.0.238",
"Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2- final",
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.0.0-preview2-final",
"imports": [
"portable-net45+win8+dnxcore50",
"portable-net45+win8"
]
}
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"net450",
"portable-net45+win8"
]
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},
"publishOptions": {
"include": [
"wwwroot",
"Views",
"Areas/**/Views",
"appsettings.json",
"web.config"
]
},
"scripts": {
"prepublish": [ "bower install", "dotnet bundle" ],
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
迁移无法识别列的名称更改。我不知道代码中是否存在问题,或者因为带有Npgsql的EF Core仍然不支持注释。
有什么想法吗?
谢谢...