1

We've finally reached a point in our dev where we're performing CRUD operations, most of which works, apart from our own referenced key clean up (we're using a old-pre-designed database).

The problem we're having is that our objects that have composite keys don't appear to be updating - even when changed!

At current I am simply trying to update the Screen Number property and then calling flush. There are some other operations that happen (such as delete), but they are expected and irrelevant to this example.

Thanks!

My mappings are below:

public class Xref_el_c : ClassMap<Xref_EntityCaseEntity>
{
    public Xref_el_c()
    {
        Table("Xref_el_c");

        CompositeId()
        .KeyProperty(x => x.EntityRef, "xelc_el_ref")
        .KeyProperty(x => x.Case, "xelc_c_ref")
        .KeyProperty(x => x.ScreenNumber, "xelc_screen");
    }
}

/object/

public class Xref_EntityCaseEntity : BaseCompositeEntity
{
    public virtual int EntityRef { get; set; }

    public virtual int Case { get; set; }

    public virtual int? ScreenNumber { get; set; }

    public override bool Equals(object obj)
    {
        if (obj == null)
            return false;

        Xref_EntityCaseEntity xe = obj as Xref_EntityCaseEntity;

        if (xe == null)
            return false;

        return EntityRef == xe.EntityRef && Case == xe.Case && ScreenNumber == xe.ScreenNumber;
    }

    public override int GetHashCode()
    {
        return (EntityRef + "|" + Case + "|" + ScreenNumber).GetHashCode();
    }
}

Code doing the work below:

IEnumerable<Xref_EntityCaseEntity> xrefs = GetEntityCrossReferenceLinks(entCode, caseRef);

            foreach (var item in xrefs)
            {
                if (item.EntityRef != reference) //because the deletion won't actually happen until Dispose() is called, we could essentially queue an update for a delete item.
                {
                    if (item.ScreenNumber == null || (item.ScreenNumber == 0 || item.ScreenNumber == 0))
                    {
                        item.ScreenNumber = 1;

                    }
                    else
                    {
                        item.ScreenNumber = item.ScreenNumber - 1;
                    }

                    _entityToCaseXref.Update(item);
                }
            }

The update marked here simply calls Session.Update() and Session.Flush()

Stuart.Sklinar
  • 3,683
  • 4
  • 35
  • 89

0 Answers0