EFCore.ModelBuilderExtensions
Initial release.
诱因对实体框架核心的库。
当前,这仅包括设置SQL数据库的默认值。
此软件包可在Nuget上安装。
Install-Package EFCore.ModelBuilderExtensions -Version 1.0.0
dotnet add package EFCore.ModelBuilderExtensions --version 1.0.0
在模型上下文中,使用OnModelCreating方法内的SetSQLDEFAULTVALUES()扩展方法。
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.SetSQLDefaultValues();
}
在EFCore.modelbuilderextensions.tributes instity Framework模型类中添加SqlDefaultValue属性。
public class ExampleClass
{
[SqlDefaultValue("Hello World")]
public string ClassProperty { get; set; }
[SqlDefaultValue("getdate()")]
public DateTime DateProperty { get; set; }
}
现在您已经准备好了!
在软件包管理器控制台中使用标准Add-Migration命令。如果您转到构建的迁移,您会注意到defaultValueSql属性是针对列定义设置的。