dodanie encji raportu wraz z mappingiem

This commit is contained in:
Kamil Ryżek 2024-06-07 23:53:09 +02:00
parent c4f62ec62b
commit 100885c3c4
2 changed files with 53 additions and 0 deletions

View File

@ -0,0 +1,23 @@
using FirmTracker_Server.nHibernate.Expenses;
using FirmTracker_Server.nHibernate.Transactions;
namespace FirmTracker_Server.nHIbernate.Reports
{
public class Report
{
public virtual int Id { get; set; }
public virtual DateTime FromDate { get; set; }
public virtual DateTime ToDate { get; set; }
public virtual IList<Transaction> Transactions { get; set;} = new List<Transaction>();
public virtual IList<Expense> Expenses { get; set; } = new List<Expense>();
public virtual decimal TotalIncome { get; set; }
public virtual decimal TotalExpenses { get; set; }
public virtual decimal TotalBalance { get; set; }
public Report() {
Transactions = new List<Transaction>();
Expenses = new List<Expense>();
}
}
}

View File

@ -0,0 +1,30 @@
using FluentNHibernate.Mapping;
namespace FirmTracker_Server.nHIbernate.Reports
{
public class ReportMapping : ClassMap<Report>
{
public ReportMapping()
{
Table("Reports");
Id(x => x.Id).GeneratedBy.Identity();
Map(x => x.FromDate);
Map(x => x.ToDate);
Map(x => x.TotalIncome);
Map(x => x.TotalExpenses);
Map(x => x.TotalBalance);
HasManyToMany(x => x.Transactions)
.Cascade.All()
.Table("ReportTransactions")
.ParentKeyColumn("ReportId")
.ChildKeyColumn("TransactionId");
HasManyToMany(x => x.Expenses)
.Cascade.All()
.Table("ReportExpenses")
.ParentKeyColumn("ReportId")
.ChildKeyColumn("ExpenseId");
}
}
}