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,49 +1,39 @@
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
namespace Elwig.Models {
[Table("area_commitment"), PrimaryKey("VNr", "KgNr", "GstNr")]
public class AreaCommitment {
[Table("area_commitment"), PrimaryKey("VNr")]
public class AreaCom {
[Column("vnr")]
public int VNr { get; set; }
[Column("kgnr")]
public int KgNr { get; set; }
[Column("gstnr")]
public string? GstNr { get; set; }
[Column("rdnr")]
public int? RdNr { get; set; }
[Column("area")]
public int Area { get; set; }
[Column("sortid")]
public string SortId { get; set; }
[Column("attrid")]
public string? AttrId { get; set; }
[Column("cultid")]
public string CultId { get; set; }
[ForeignKey("KgNr")]
public virtual WbKg Kg { get; private set; }
[ForeignKey("KgNr, RdNr")]
public virtual WbRd? Rd { get; private set; }
[ForeignKey("VNr")]
public virtual Contract Contract { get; private set; }
[ForeignKey("SortId")]
public virtual WineVar WineVar { get; private set; }
[ForeignKey("AttrId")]
public virtual WineAttr WineAttr { get; private set; }
[ForeignKey("CultId")]
public virtual WineCult WineCult { get; private set; }
[InverseProperty("AreaCom")]
public virtual ISet<AreaComParcel> Parcels { get; private set; }
[InverseProperty("AreaCom")]
public virtual ISet<AreaComAttr> AttributeEntries { get; private set; }
[NotMapped]
public IEnumerable<WineAttr> Attributes => AttributeEntries.Select(e => e.WineAttr);
}
}

View File

@ -0,0 +1,19 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;
namespace Elwig.Models {
[Table("area_commitment_attribute"), PrimaryKey("VNr", "AttrId")]
public class AreaComAttr {
[Column("vnr")]
public int VNr { get; set; }
[Column("attrid")]
public string AttrId { get; set; }
[ForeignKey("VNr")]
public virtual AreaCom AreaCom { get; private set; }
[ForeignKey("AttrId")]
public virtual WineAttr WineAttr { get; private set; }
}
}

View File

@ -0,0 +1,31 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;
namespace Elwig.Models {
[Table("area_commitment_parcel"), PrimaryKey("VNr", "KgNr", "GstNr")]
public class AreaComParcel {
[Column("vnr")]
public int VNr { get; set; }
[Column("kgnr")]
public int KgNr { get; set; }
[Column("gstnr")]
public string? GstNr { get; set; }
[Column("rdnr")]
public int? RdNr { get; set; }
[Column("area")]
public int? Area { get; set; }
[ForeignKey("KgNr")]
public virtual WbKg Kg { get; private set; }
[ForeignKey("KgNr, RdNr")]
public virtual WbRd? Rd { get; private set; }
[ForeignKey("VNr")]
public virtual AreaCom AreaCom { get; private set; }
}
}

View File

@ -3,7 +3,7 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace Elwig.Models {
[Table("member_billing_address"), PrimaryKey("MgNr")]
public class BillingAddress {
public class BillingAddr {
[Column("mgnr")]
public int MgNr { get; set; }

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;
}
}

22
Elwig/Models/Currency.cs Normal file
View File

@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;
namespace Elwig.Models {
[Table("currency"), PrimaryKey("Code")]
public class Currency {
[Column("code")]
public string Code { get; private set; }
[Column("name")]
public string Name { get; private set; }
[Column("symbol")]
public string? Symbol { get; private set; }
[Column("one_euro")]
public int? OneEuroValue { get; private set; }
[NotMapped]
public decimal? OneEuro => OneEuroValue / 1_000_000;
}
}

View File

@ -38,10 +38,30 @@ namespace Elwig.Models {
public string? Birthday { get; set; }
[Column("entry_date")]
public string? EntryDate { get; set; }
public string? EntryDateString { get; set; }
[NotMapped]
public DateOnly? EntryDate {
get {
return EntryDateString != null ? DateOnly.ParseExact(EntryDateString, "yyyy-MM-dd") : null;
}
set {
EntryDateString = value?.ToString("yyyy-MM-dd");
}
}
[Column("exit_date")]
public string? ExitDate { get; set; }
public string? ExitDateString { get; set; }
[NotMapped]
public DateOnly? ExitDate {
get {
return ExitDateString != null ? DateOnly.ParseExact(ExitDateString, "yyyy-MM-dd") : null;
}
set {
ExitDateString = value?.ToString("yyyy-MM-dd");
}
}
[Column("business_shares")]
public int BusinessShares { get; set; }
@ -125,7 +145,7 @@ namespace Elwig.Models {
public virtual ISet<Contract> Contracts { get; private set; }
[InverseProperty("Member")]
public virtual BillingAddress BillingAddress { get; private set; }
public virtual BillingAddr BillingAddress { get; private set; }
public int SearchScore(IEnumerable<string> keywords) {
keywords = keywords.Where(s => s.Length >= 2 || (s.Length > 0 && s.All(c => char.IsDigit(c))));

46
Elwig/Models/Season.cs Normal file
View File

@ -0,0 +1,46 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.ComponentModel.DataAnnotations.Schema;
namespace Elwig.Models {
[Table("season"), PrimaryKey("Year")]
public class Season {
[Column("year")]
public int Year { get; set; }
[Column("currency")]
public string CurrencyCode { get; set; }
[Column("precision")]
public int Precision { get; set; }
[Column("start_date")]
public string? StartDateString { get; set; }
[NotMapped]
public DateOnly? StartDate {
get {
return StartDateString != null ? DateOnly.ParseExact(StartDateString, "yyyy-MM-dd") : null;
}
set {
StartDateString = value?.ToString("yyyy-MM-dd");
}
}
[Column("end_date")]
public string? EndDateString { get; set; }
[NotMapped]
public DateOnly? EndDate {
get {
return EndDateString != null ? DateOnly.ParseExact(EndDateString, "yyyy-MM-dd") : null;
}
set {
EndDateString = value?.ToString("yyyy-MM-dd");
}
}
[ForeignKey("CurrencyCode")]
public virtual Currency Currency { get; private set; }
}
}

View File

@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore;
using Elwig.Helpers;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations.Schema;
namespace Elwig.Models {
@ -10,13 +11,16 @@ namespace Elwig.Models {
[Column("origin_level")]
public int? OriginLevel { get; private set; }
[Column("predicate")]
public bool IsPredicate { get; private set; }
[Column("min_kmw")]
public double? MinKmw { get; private set; }
[NotMapped]
public double? MinOe => MinKmw != null ? Utils.KmwToOe((double)MinKmw) : null;
[Column("name")]
public string Name { get; private set; }
[Column("from_kmw")]
public double? FromKmw { get; private set; }
[Column("to_kmw")]
public double? ToKmw { get; private set; }
}
}