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屬性是針對列定義設置的。