How to map two objects that reference each other in NHibernate? -


I have a class that looks like this:

  public class jobs { Public company company {Get; Set;} Public Job JobForCompanyA {get; Set;} Public Job JobForCompanyB {get; Work for two companies will refer to each other, for example:    var jobA = new job {Company = Company.}  CompanyA}; Var jobB = New job {Company = Company. Compbi B}; JobA.JobForCompanyB = jobB; JobB.JobForCompanyA = jobA;  

With this problem, if I map them as common-to-many in NHibernate, then they can not save them ... because every Job object is the second reference Let's get a PK to save one, but you can not do this because it does not reference other (unsaved) jobs, so you have chicken and egg problem.

From DB's perspective, I can mapping the tables which are Jobs for company A for the jobs for Company B. Is changing my entity object a way to use NHibernate without changing it? I know that I can add list properties and hacks to normalize many-to-many relationships, but it should be a pattern that provides better solution for someone.

I'm Fluent NiBinet, you can give me a solution using Fluent NIBNET or NHBernet XML Mappings.

This fluent mapping refers to many properties of the same type, here I am assuming that your In the job table, you have two columns (JobID and Jobbid), which refers to other jobs (via job ID).

References (X => X. JobForCompanyA, "JobAId"); References (X => X. JobForCompanyB, "JobBId");


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -