我用一些表和列創建了我的第一個初始遷移,但我看到了一個東西,我的所有欄位都不為空,并且對于我想要為空的每個欄位(幾乎所有)我需要指定IsRequired(false)

有一種方法可以將所有欄位設定為可為空,并且只為我想要的那些欄位呼叫 isRequired() (true)?
我不想使用資料注釋或其他東西,只有 Fluent Api,所以只有在 Fluent Api 中存在全域設定,否則我將把每個欄位都放入 IsRequired。我想將模型與 FluentApi 組態檔分離,因為將來如果我想使用另一個 ORM,我只需要更改 FluentApi 組態檔。
uj5u.com熱心網友回復:
在您的物體中,您可以將屬性設定為可為空
Public class Booking
{
public Guid? MyProperty{ get; set; }
public int? MyProperty{ get; set; }
public decimal? MyProperty{ get; set; }
}
或使用JetBrains.Annotations
using JetBrains.Annotations;
Public class Booking
{
[CanBeNull]
public Guid MyProperty{ get; set; }
[CanBeNull]
public int MyProperty{ get; set; }
[CanBeNull]
public decimal MyProperty{ get; set; }
}
uj5u.com熱心網友回復:
當你設定你的類時,你可以使用可為空的值型別示例:
public class a {
int? a { get; set; }
}
uj5u.com熱心網友回復:
我不想使用資料注釋或其他東西,只有 Fluent Api,所以只有在 Fluent Api 中存在全域設定,否則我將把每個欄位都放入 IsRequired。我想將模型與 FluentApi 組態檔分離,因為將來如果我想使用另一個 ORM,我只需要更改 FluentApi 組態檔。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/517023.html
