For example, consider this Invoice class:
public class Invoice
{
public int InvoiceId { get; set; }
public decimal Amount { get; set; }
}
You can do it with fluent API:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Invoice>()
.Property(i => i.Amount)
.HasColumnType("Money");
}
Or you can do it with Data Annotations:
public class Invoice
{
public int InvoiceId { get; set; }
[Column(TypeName="Money")]
public decimal Amount { get; set; }
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…