All the mapped properties are public & virtual. I've attached the project class/mappings as well as the conflict class/mapping mentioned in the post.
On Monday, November 2, 2015 at 10:28:22 AM UTC-5, PeSo wrote:
>
> Sounds like a mapping problem. Are all the properties virtual and public
> (or protected)?
> Can you post hbm.xml or mapping code?
>
> Best regards,
>
> Peter
>
> Am Sonntag, 1. November 2015 17:49:10 UTC+1 schrieb Jeffrey Becker:
>>
>> I'm receiving an error which I don't understand when trying to save my
>> Project entity. The Project class is an abstract base class which has a
>> bunch of basic functionality and several concrete implementations.
>>
>> My method:
>>
>> public void Handle(ProjectChanged message)
>> {
>> using (var tx = _session.BeginTransaction())
>> {
>> var project = _session.Get<Project>(message.ProjectId);
>> var conflictingLocationStubs = GetConflictingLocationStubs(
>> project);
>>
>>
>> ResolveRemovedConflicts(conflictingLocationStubs, project);
>> UpdateExistingConflicts(conflictingLocationStubs, project);
>> AddNewConflicts(conflictingLocationStubs, project);
>> UpdateConflictedStatus(project);
>> tx.Commit();
>> }
>> }
>>
>>
>> This code finds other projects in the database with conflicting locations
>> and adds/updates/removes Conflict records appropriately. This code
>> produces an error:
>> NHibernate.PropertyNotFoundExceptionCould not find a getter for property
>> 'LinearFeetPermitted' in class 'ProjectProxy'
>>
>> I'm perplexed because the code itself only ever operates on the base
>> project class. Do I have to call Get against the concrete implementation
>> classes or something?
>>
>
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.
Project.hbm.xml
Description: XML document
StandardStreetsProject.hbm.xml
Description: XML document
Tier1Project.hbm.xml
Description: XML document
Tier2Project.hbm.xml
Description: XML document
TurnOffOnProject.hbm.xml
Description: XML document
AnnualStreetsProject.hbm.xml
Description: XML document
EmergencyProject.hbm.xml
Description: XML document
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Reflection;
using System.Security.Cryptography.X509Certificates;
using GpisReplacement.Arch;
using GpisReplacement.Domain.Enums;
using NHibernate.Util;
namespace GpisReplacement.Domain
{
public abstract class Project : EqualityAndHashCodeProvider<Project,long>
{
public override long Id { get; set; }
public virtual bool IsEmergency { get; set; }
public virtual bool IsAccelerated { get; set; }
public abstract ProjectClassification ProjectClassification { get; }
[Required]
[MaxLength(75)]
public virtual string ProjectName { get; set; }
public virtual WorkType WorkType { get; set; }
public virtual WorkBy WorkBy { get; set; }
public virtual bool CombinedProject { get; set; }
public virtual bool FederalProject { get; set; }
[MaxLength(30)]
public virtual string ProjectNumber { get; set; }
public virtual ProjectStatus ProjectStatus { get; set; }
public virtual bool DoNotTrackConflicts { get; set; }
public virtual int BufferMonths { get; set; }
public virtual string ImportSessionId { get; set; }
public virtual long LinearFeetEstimated { get; set; }
public virtual bool IsActive { get; set; }
public virtual Organization Organization { get; set; }
public virtual Ordinance Ordinance { get; set; }
public virtual ICollection<ProjectContact> ProjectContacts { get; set; }
public virtual ICollection<DocumentMetaData> ProjectDocuments { get; set; }
//public virtual ICollection<Phase> ProjectPhases { get; set; }
public virtual IDictionary<PhaseName, Phase> ProjectPhases { get; set; }
public virtual ICollection<Conflict> Conflicts { get; set; }
protected Project()
{
ProjectPhases = new Dictionary<PhaseName, Phase>();
ProjectContacts = new HashSet<ProjectContact>();
Conflicts = new List<Conflict>();
}
public static Project Create(ProjectClassification projectClass)
{
Type[] types = Assembly.GetExecutingAssembly().GetTypes();
foreach (Type type in types.Where(t => t.IsSubclassOf(typeof(Project))))
{
Project obj = (Project)Activator.CreateInstance(type);
obj.IsActive = true;
if (obj.ProjectClassification == projectClass)
{
obj.InitializePhases();
return obj;
}
}
throw new Exception("Type " + projectClass + " not found.");
}
public virtual void MoveToNextPhase( DateTime closedate)
{
var currentPhase = CurrentPhase;
//store contacts in a different var - they disappear once "IsCurrentPhase" is changed
var currentContacts = currentPhase.Contacts;
currentPhase.ActEndDate = closedate;
currentPhase.IsCurrentPhase = false;
//current phase isn't referencing the current phase contacts
Phase nextPhase = FindNextPhase(currentPhase);
if (nextPhase == null) return;
nextPhase.IsCurrentPhase = true;
//copy contacts
foreach (var c in currentContacts)
{
nextPhase.AddContact(c.Contact, c.PrimaryPhaseContact);
}
foreach (var d in currentPhase.Districts)
{
nextPhase.AddDistrict(d);
//d.Phases.Add(nextPhase);
}
foreach (var l in currentPhase.PhaseLocations)
{
var newLocation = l.Clone() as ProjectLocation;
nextPhase.AddLocation(newLocation);
foreach (var c in l.ConflictingLocations)
{
c.UpdateProjectLocation(l, newLocation);
}
}
}
public virtual Phase CurrentPhase
{
get
{
if (ProjectPhases == null || ProjectPhases.Count == 0) return null;
return ProjectPhases.Single(p => p.Value.IsCurrentPhase).Value;
}
}
protected abstract Phase FindNextPhase(Phase currentPhase);
public abstract void InitializePhases();
public virtual void AddContact(Contact contact)
{
if (!ProjectContacts.Any(x => x.Contact.Id == contact.Id))
{
this.ProjectContacts.Add(new ProjectContact
{
Contact = contact,
Project = this
});
}
}
public virtual void AddDocument(DocumentMetaData document)
{
if (this.ProjectDocuments == null)
{
this.ProjectDocuments = new HashSet<DocumentMetaData>();
}
if (!this.ProjectDocuments.Contains(document))
{
ProjectDocuments.Add(document);
}
}
public virtual bool IsPermitted()
{
var ispermitted =
(typeof(ProjectClassification).GetField(this.ProjectClassification.ToString())
.GetCustomAttribute<ProjectClassificationRestrictionAttribute>().IsPermitted);
return ispermitted;
}
public virtual void RemoveContact(Contact contact)
{
var pclist = this.ProjectContacts.Where(x => x.Contact == contact).ToList();
if (pclist.Any())
{
foreach (var pc in pclist)
{
this.ProjectContacts.Remove(pc);
}
}
}
public virtual Tuple<DateTime, DateTime> GetConflictWindow(TimeSpan conflictWindow)
{
var constructionPhase = ProjectPhases[PhaseName.Construction];
var start = (constructionPhase.ActStartDate ?? constructionPhase.EstStartDate).Value.Subtract(conflictWindow);
var end = (constructionPhase.ActEndDate ?? constructionPhase.EstEndDate).Value.Add(conflictWindow);
return Tuple.Create(start, end);
}
public override string ToString()
{
return String.Format("{0} ({1}", ProjectName, ProjectClassification);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using GpisReplacement.Domain.Enums;
namespace GpisReplacement.Domain
{
public class StandardStreetsProject: Project
{
private const ProjectClassification Classification = ProjectClassification.StandardStreets;
public virtual string BidNumber { get; set; }
public virtual DateTime? BidDate { get; set; }
public override ProjectClassification ProjectClassification
{
get { return Classification; }
}
protected override Phase FindNextPhase(Phase currentPhase)
{
if (currentPhase.PhaseName == PhaseName.Planning)
return ProjectPhases[PhaseName.Design];
if (currentPhase.PhaseName == PhaseName.Design)
return ProjectPhases[PhaseName.Construction];
return null;
}
public override void InitializePhases()
{
var set = new HashSet<Phase>
{
new Phase
{
Project = this,
PhaseName = PhaseName.Planning,
EstStartDate = DateTime.Today,
ActStartDate = DateTime.Today,
IsCurrentPhase = true
},
new Phase
{
Project = this,
PhaseName = PhaseName.Design,
IsCurrentPhase = false
},
new Phase
{
Project = this,
PhaseName = PhaseName.Construction,
IsCurrentPhase = false
}
};
ProjectPhases = set.ToDictionary(x => x.PhaseName);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using GpisReplacement.Arch;
using GpisReplacement.Domain.Db;
using GpisReplacement.Domain.Enums;
using NHibernate.Util;
namespace GpisReplacement.Domain
{
public class Tier1Project : Project
{
private const ProjectClassification Classification = ProjectClassification.Tier1;
public virtual long LinearFeetPermitted { get; set; }
public virtual DateTime? DateOfPermitApp { get; set; }
public virtual DateTime? DateOfCompletionAcceptance { get; set; }
public virtual ICollection<ClearanceRequest> ClearanceRequests { get; set; }
public virtual ICollection<Permit> Permits { get; set; }
public override ProjectClassification ProjectClassification
{
get { return Classification; }
}
protected override Phase FindNextPhase(Phase currentPhase)
{
if (currentPhase.PhaseName == PhaseName.Design)
return ProjectPhases[PhaseName.Permit];
if (currentPhase.PhaseName == PhaseName.Permit)
return ProjectPhases[PhaseName.Construction];
return null;
}
public override void InitializePhases()
{
var set = new HashSet<Phase>
{
new Phase
{
Project = this,
PhaseName = PhaseName.Design,
EstStartDate = DateTime.Today,
ActStartDate = DateTime.Today,
IsCurrentPhase = true
},
new Phase
{
Project = this,
PhaseName = PhaseName.Permit,
IsCurrentPhase = false
},
new Phase
{
Project = this,
PhaseName = PhaseName.Construction,
IsCurrentPhase = false
}
};
ProjectPhases = set.ToDictionary(x => x.PhaseName);
}
public Tier1Project()
{
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GpisReplacement.Domain.Db;
using GpisReplacement.Domain.Enums;
namespace GpisReplacement.Domain
{
public class Tier2Project : Project
{
public static ProjectClassification Classification = ProjectClassification.Tier2;
public virtual long LinearFeetPermitted { get; set; }
public virtual DateTime? DateOfPermitApp { get; set; }
public virtual DateTime? DateOfCompletionAcceptance { get; set; }
public virtual ICollection<ClearanceRequest> ClearanceRequests { get; set; }
public virtual ICollection<Permit> Permits { get; set; }
public override ProjectClassification ProjectClassification
{
get { return Classification; }
}
protected override Phase FindNextPhase(Phase currentPhase)
{
if (currentPhase.PhaseName == PhaseName.Planning)
return ProjectPhases[PhaseName.Design];
if (currentPhase.PhaseName == PhaseName.Design)
return ProjectPhases[ PhaseName.Permit];
if (currentPhase.PhaseName == PhaseName.Permit)
return ProjectPhases[PhaseName.Construction];
return null;
}
public override void InitializePhases()
{
var set = new HashSet<Phase>
{
new Phase
{
Project = this,
PhaseName = PhaseName.Planning,
EstStartDate = DateTime.Today,
ActStartDate = DateTime.Today,
IsCurrentPhase = true
},
new Phase
{
Project = this,
PhaseName = PhaseName.Design,
IsCurrentPhase = false
},
new Phase
{
Project = this,
PhaseName = PhaseName.Permit,
IsCurrentPhase = false
},
new Phase
{
Project = this,
PhaseName = PhaseName.Construction,
IsCurrentPhase = false
}
};
ProjectPhases = set.ToDictionary(x => x.PhaseName);
}
public Tier2Project()
{
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GpisReplacement.Domain.Db;
using GpisReplacement.Domain.Enums;
namespace GpisReplacement.Domain
{
public class TurnOffOnProject : Project
{
public static readonly ProjectClassification Classification = ProjectClassification.TurnOffOn;
public virtual long LinearFeetPermitted { get; set; }
public virtual DateTime? DateOfPermitApp { get; set; }
public virtual DateTime? DateOfCompletionAcceptance { get; set; }
public virtual ICollection<ClearanceRequest> ClearanceRequests { get; set; }
public virtual ICollection<Permit> Permits { get; set; }
public override ProjectClassification ProjectClassification
{
get { return Classification; }
}
protected override Phase FindNextPhase(Phase currentPhase)
{
if (currentPhase.PhaseName == PhaseName.Permit)
return ProjectPhases[PhaseName.Construction];
return null;
}
public override void InitializePhases()
{
var set = new HashSet<Phase>
{
new Phase
{
Project = this,
PhaseName = PhaseName.Permit,
EstStartDate = DateTime.Today,
ActStartDate = DateTime.Today,
IsCurrentPhase = true
},
new Phase
{
Project = this,
PhaseName = PhaseName.Construction,
IsCurrentPhase = false
}
};
ProjectPhases = set.ToDictionary(x => x.PhaseName);
}
public TurnOffOnProject()
{
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using GpisReplacement.Domain.Enums;
namespace GpisReplacement.Domain
{
public class AnnualStreetsProject : Project
{
private const ProjectClassification Classification = ProjectClassification.AnnualStreets;
public virtual string BidNumber { get; set; }
public virtual DateTime? BidDate { get; set; }
public virtual int EstTotalArea { get; set; }
public virtual int ActualTotalArea { get; set; }
public virtual int PropTotalTons { get; set; }
public virtual int TotalTonsUsed { get; set; }
public virtual AnnualProjectTypes AnnualProjectType {get;set;}
public override ProjectClassification ProjectClassification
{
get { return Classification; }
}
public AnnualStreetsProject()
{
}
protected override Phase FindNextPhase(Phase currentPhase)
{
return null;
}
public override void InitializePhases()
{
ProjectPhases = new Dictionary<PhaseName, Phase>
{
{
PhaseName.Construction,
new Phase {PhaseName = PhaseName.Construction, IsCurrentPhase = true, Project = this}
}
};
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using GpisReplacement.Domain.Db;
using GpisReplacement.Domain.Enums;
namespace GpisReplacement.Domain
{
public class EmergencyProject : Project
{
public EmergencyProject()
{
}
[MaxLength(6)]
public virtual string EUNNumber { get; set; }
public virtual long LinearFeetPermitted { get; set; }
public virtual DateTime? DateOfPermitApp { get; set; }
public virtual DateTime? DateOfCompletionAcceptance { get; set; }
public virtual ICollection<ClearanceRequest> ClearanceRequests { get; set; }
public virtual ICollection<Permit> Permits { get; set; }
public override ProjectClassification ProjectClassification
{
get { return ProjectClassification.Emergency; }
}
protected override Phase FindNextPhase(Phase currentPhase)
{
if (currentPhase.PhaseName == PhaseName.Permit)
return ProjectPhases[PhaseName.Construction];
return null;
}
public override void InitializePhases()
{
ProjectPhases = new Dictionary<PhaseName, Phase>
{
{
PhaseName.Permit,
new Phase
{
Project = this,
PhaseName = PhaseName.Permit,
EstStartDate = DateTime.Today,
ActStartDate = DateTime.Today,
IsCurrentPhase = true
}
},
{
PhaseName.Construction,
new Phase {Project = this, PhaseName = PhaseName.Construction, IsCurrentPhase = false}
},
};
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GpisReplacement.Arch;
using GpisReplacement.Domain.Enums;
namespace GpisReplacement.Domain
{
public class Conflict : EqualityAndHashCodeProvider<Conflict, long>
{
public Conflict()
{
Locations = new HashSet<ConflictingLocation>();
Projects = new Dictionary<ConflictEnd, Project>();
Resolutions = new Dictionary<ConflictEnd, Resolution>();
Events = new Dictionary<ConflictEnd, Event>();
}
public override long Id { get; set; }
public virtual string ConflictNumber { get; set; }
public virtual bool IsResolved { get; set; }
public virtual DateTime? ResolutionDate { get; set; }
public virtual string Reason { get; set; }
public virtual DateTime? EscalationDate { get; set; }
public virtual ICollection<ConflictingLocation> Locations { get; protected set; }
public virtual IDictionary<ConflictEnd, Project> Projects { get; protected set; }
public virtual IDictionary<ConflictEnd, Event> Events { get; protected set; }
public virtual IDictionary<ConflictEnd, Resolution> Resolutions { get; protected set; }
public virtual bool IsInConflictWithAnnualStreets
{
get { return IsInConflictWith(ProjectClassification.AnnualStreets); }
}
public virtual bool IsInConflictWithTier1
{
get { return IsInConflictWith(ProjectClassification.Tier1); }
}
public virtual bool IsInConflictWithTier2
{
get { return IsInConflictWith(ProjectClassification.Tier2);}
}
private bool IsInConflictWith(ProjectClassification projectClassification)
{
return Projects[ConflictEnd.Left].ProjectClassification == projectClassification
|| (Projects.ContainsKey(ConflictEnd.Right) && Projects[ConflictEnd.Right].ProjectClassification == projectClassification);
}
public virtual void AddResolution(ConflictEnd side, Resolution resolution)
{
Resolutions[side] = resolution;
resolution.Conflict = this;
}
public virtual void AddProject(ConflictEnd side, Project project)
{
Projects[side] = project;
project.Conflicts.Add(this);
}
public virtual void AddEvent(ConflictEnd side, Event evt)
{
Events[side] = evt;
evt.Conflicts.Add(this);
}
public virtual void AddLocation(ConflictingLocation loc)
{
loc.Conflict = this;
this.Locations.Add(loc);
}
}
}
Conflict.hbm.xml
Description: XML document
