From 812ee1b8ebd2ed2afd7aa147aaf72f83b78dad59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Ry=C5=BCek?= Date: Sat, 8 Jun 2024 00:24:12 +0200 Subject: [PATCH] =?UTF-8?q?mapowanie=20relacji=20mi=C4=99dzy=20raportem=20?= =?UTF-8?q?a=20transakcj=C4=85/wydatkiem?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nHIbernate/Expenses/Expense.cs | 5 ++++- nHIbernate/Expenses/ExpenseMapping.cs | 6 ++++++ nHIbernate/Reports/Report.cs | 2 +- nHIbernate/Reports/ReportMapping.cs | 2 +- nHIbernate/SessionFactory.cs | 3 ++- nHibernate/Transactions/Transaction.cs | 2 ++ nHibernate/Transactions/Transaction2.cs | 2 ++ nHibernate/Transactions/Transaction2Mapping.cs | 6 ++++++ nHibernate/Transactions/TransactionMapping.cs | 6 ++++++ 9 files changed, 30 insertions(+), 4 deletions(-) diff --git a/nHIbernate/Expenses/Expense.cs b/nHIbernate/Expenses/Expense.cs index f99cc0a..788655b 100644 --- a/nHIbernate/Expenses/Expense.cs +++ b/nHIbernate/Expenses/Expense.cs @@ -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 Reports { get; set; } = new List(); } } diff --git a/nHIbernate/Expenses/ExpenseMapping.cs b/nHIbernate/Expenses/ExpenseMapping.cs index ad2468d..039a58b 100644 --- a/nHIbernate/Expenses/ExpenseMapping.cs +++ b/nHIbernate/Expenses/ExpenseMapping.cs @@ -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"); + } } } diff --git a/nHIbernate/Reports/Report.cs b/nHIbernate/Reports/Report.cs index 2597d0b..a763a61 100644 --- a/nHIbernate/Reports/Report.cs +++ b/nHIbernate/Reports/Report.cs @@ -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 { diff --git a/nHIbernate/Reports/ReportMapping.cs b/nHIbernate/Reports/ReportMapping.cs index 5035cc4..e0c0fa2 100644 --- a/nHIbernate/Reports/ReportMapping.cs +++ b/nHIbernate/Reports/ReportMapping.cs @@ -1,5 +1,5 @@ using FluentNHibernate.Mapping; -namespace FirmTracker_Server.nHIbernate.Reports +namespace FirmTracker_Server.nHibernate.Reports { public class ReportMapping : ClassMap { diff --git a/nHIbernate/SessionFactory.cs b/nHIbernate/SessionFactory.cs index 6562a29..71f7ad9 100644 --- a/nHIbernate/SessionFactory.cs +++ b/nHIbernate/SessionFactory.cs @@ -33,7 +33,8 @@ namespace FirmTracker_Server.nHibernate .AddFromAssemblyOf() .AddFromAssemblyOf() .AddFromAssemblyOf() - .AddFromAssemblyOf(); + .AddFromAssemblyOf() + .AddFromAssemblyOf(); }) .ExposeConfiguration(cfg => new SchemaExport(cfg).Create(true, true)) //SchemaUpdate . Execute dla only update .BuildSessionFactory(); diff --git a/nHibernate/Transactions/Transaction.cs b/nHibernate/Transactions/Transaction.cs index 879c033..f860a5d 100644 --- a/nHibernate/Transactions/Transaction.cs +++ b/nHibernate/Transactions/Transaction.cs @@ -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 Reports { get; set; } = new List(); public Transaction() { diff --git a/nHibernate/Transactions/Transaction2.cs b/nHibernate/Transactions/Transaction2.cs index f6ef4a0..5400ee9 100644 --- a/nHibernate/Transactions/Transaction2.cs +++ b/nHibernate/Transactions/Transaction2.cs @@ -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 Reports { get; set; } = new List(); public Transaction2() { diff --git a/nHibernate/Transactions/Transaction2Mapping.cs b/nHibernate/Transactions/Transaction2Mapping.cs index 931456d..9265f00 100644 --- a/nHibernate/Transactions/Transaction2Mapping.cs +++ b/nHibernate/Transactions/Transaction2Mapping.cs @@ -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"); } } } diff --git a/nHibernate/Transactions/TransactionMapping.cs b/nHibernate/Transactions/TransactionMapping.cs index 3a24b5b..5aa2966 100644 --- a/nHibernate/Transactions/TransactionMapping.cs +++ b/nHibernate/Transactions/TransactionMapping.cs @@ -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"); } } }