Update model database schema

This commit is contained in:
2023-04-16 15:08:15 +02:00
parent 0333e8a5c5
commit 6e0b59da4b
14 changed files with 232 additions and 72 deletions

View File

@ -1,7 +1,6 @@
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
namespace Elwig.Models {
[Table("contract"), PrimaryKey("VNr")]
@ -12,19 +11,35 @@ namespace Elwig.Models {
[Column("mgnr")]
public int MgNr { get; set; }
[Column("date")]
public string? DateString { get; set; }
[NotMapped]
public DateOnly? Date {
get {
return DateString != null ? DateOnly.ParseExact(DateString, "yyyy-MM-dd") : null;
}
set {
DateString = value?.ToString("yyyy-MM-dd");
}
}
[Column("year_from")]
public int YearFrom { get; set; }
[Column("year_to")]
public int? YearTo { get; set; }
[Column("comment")]
public string? Comment { get; set; }
[ForeignKey("MgNr")]
public virtual Member Member { get; private set; }
[InverseProperty("Contract")]
public virtual ISet<AreaCommitment> AreaCommitments { get; private set; }
public virtual AreaCom? AreaCom { get; private set; }
[NotMapped]
public int Area => AreaCommitments.Select(a => a.Area).Sum();
public int? Area => AreaCom?.Area;
}
}