mapowanie relacji między raportem a transakcją/wydatkiem

This commit is contained in:
Kamil Ryżek 2024-06-08 00:24:12 +02:00
parent 100885c3c4
commit 812ee1b8eb
9 changed files with 30 additions and 4 deletions

View File

@ -1,4 +1,6 @@
namespace FirmTracker_Server.nHibernate.Expenses
using FirmTracker_Server.nHibernate.Reports;
namespace FirmTracker_Server.nHibernate.Expenses
{
public class Expense
{
@ -6,5 +8,6 @@
public virtual DateTime Date { get; set; }
public virtual decimal Value { get; set; }
public virtual string Description { get; set; }
public virtual IList<Report> Reports { get; set; } = new List<Report>();
}
}

View File

@ -12,6 +12,12 @@ namespace FirmTracker_Server.nHibernate.Expenses
Map(x => x.Value);
Map(x => x.Description);
HasManyToMany(x => x.Reports)
.Cascade.All()
.Table("ReportExpenses")
.ParentKeyColumn("ExpenseId")
.ChildKeyColumn("ReportId");
}
}
}

View File

@ -1,7 +1,7 @@
using FirmTracker_Server.nHibernate.Expenses;
using FirmTracker_Server.nHibernate.Transactions;
namespace FirmTracker_Server.nHIbernate.Reports
namespace FirmTracker_Server.nHibernate.Reports
{
public class Report
{

View File

@ -1,5 +1,5 @@
using FluentNHibernate.Mapping;
namespace FirmTracker_Server.nHIbernate.Reports
namespace FirmTracker_Server.nHibernate.Reports
{
public class ReportMapping : ClassMap<Report>
{

View File

@ -33,7 +33,8 @@ namespace FirmTracker_Server.nHibernate
.AddFromAssemblyOf<Transactions.TransactionProductMapping>()
.AddFromAssemblyOf<Transactions.Transaction2Mapping>()
.AddFromAssemblyOf<Transactions.TransactionWithProductsMapping>()
.AddFromAssemblyOf<Expenses.ExpenseMapping>();
.AddFromAssemblyOf<Expenses.ExpenseMapping>()
.AddFromAssemblyOf<Reports.ReportMapping>();
})
.ExposeConfiguration(cfg => new SchemaExport(cfg).Create(true, true)) //SchemaUpdate . Execute dla only update
.BuildSessionFactory();

View File

@ -1,4 +1,5 @@
using FirmTracker_Server.nHibernate.Products;
using FirmTracker_Server.nHibernate.Reports;
using System;
using System.Collections.Generic;
using System.Linq;
@ -15,6 +16,7 @@ namespace FirmTracker_Server.nHibernate.Transactions
public virtual decimal Discount { get; set; }
public virtual string Description { get; set; }
public virtual decimal TotalPrice { get; set; }//=> TransactionProducts.Sum(tp => ((tp.Quantity * tp.UnitPrice)* ((1 - (Discount / 100)))));// (1 - (Discount / 100)));
public virtual IList<Report> Reports { get; set; } = new List<Report>();
public Transaction()
{

View File

@ -1,4 +1,5 @@
using FirmTracker_Server.nHibernate.Products;
using FirmTracker_Server.nHibernate.Reports;
using System;
using System.Collections.Generic;
using System.Linq;
@ -15,6 +16,7 @@ namespace FirmTracker_Server.nHibernate.Transactions
public virtual decimal Discount { get; set; }
public virtual string Description { get; set; }
public virtual decimal TotalPrice { get; set; }//=> TransactionProducts.Sum(tp => ((tp.Quantity * tp.UnitPrice)* ((1 - (Discount / 100)))));// (1 - (Discount / 100)));
public virtual IList<Report> Reports { get; set; } = new List<Report>();
public Transaction2()
{

View File

@ -18,6 +18,12 @@ namespace FirmTracker_Server.nHibernate.Transactions
.KeyColumn("TransactionId")
.Cascade.AllDeleteOrphan()
.Inverse(); // Ustawienie Inverse() wskazuje, że to `TransactionProduct` jest właścicielem relacji
HasManyToMany(x => x.Reports)
.Cascade.All()
.Table("ReportTransactions")
.ParentKeyColumn("TransactionId")
.ChildKeyColumn("ReportId");
}
}
}

View File

@ -18,6 +18,12 @@ namespace FirmTracker_Server.nHibernate.Transactions
.KeyColumn("TransactionId")
.Cascade.AllDeleteOrphan()
.Inverse(); // Ustawienie Inverse() wskazuje, że to `TransactionProduct` jest właścicielem relacji
HasManyToMany(x => x.Reports)
.Cascade.All()
.Table("ReportTransactions")
.ParentKeyColumn("TransactionId")
.ChildKeyColumn("ReportId");
}
}
}