so I have an entity named Event which contains many Reports (one to many) which contains many sources (many to many).
I'm facing a problem that I just cant figure out, when I'm trying to update my event, it will try to update the report because of the cascade (which is fine) and it will try to update the report's sources on the join table because of the cascade (which is fine), but for some reason it also tries to update the Source entity, which it shouldn't update because there is no change in it.
public class Event
{
public virtual IList<Report> Reports { get; set; }
public virutal int Id { get; set; }
public Event()
{
Reports = new List<Report>();
}
}
public class EventMapping : ClassMap<Event>
{
public EventMapping()
{
Table("EVENTS");
Id(x => x.Id).Column("ID").GeneratedBy.Sequence("EVENT_ID_SEQ");
HasMany(x => x.Reports).KeyCoulmn("EVENT_ID").Cascade.SaveUpdate();
}
}
public class Report
{
public virtual int Id { get; set; }
public virtual int Status { get; set; }
public virtual IList<Source> Sources { get; set; }
public Report()
{
Sources = new List<Source>();
}
}
public class ReportMapping : ClassMap<Report>
{
public ReportMapping()
{
Table("REPORTS");
Id(x => x.Id).Column("ID").GeneratedBy.Sequence("DIVUACH_ID_SEQ");
Map(x => x.Status).Column("Status");
HasManyToMany(x => x.Sources).Table("SOURCES_IN_REPORT").ParentKeyColumn("REPORT_ID").ChildKeyColumn("KOD_SOURCE").Cascade.All();
}
}
public class Source
{
public virtual int Id { get; set; }
}
public class SourceMapping : ClassMap<Source>
{
public SourceMapping()
{
Table("SOURCE");
Id(x => x.Id).Column("ID");
}
}
here is what I do and when it fails.
var eventFromDb = _session.Get<Event>(eventId);
eventFromDb.Reports.ToList().ForEach(x => x.Status = GetStatus());
_session.Update(eventFromDb);
Any idea why?