locked
NHibernate problem - Get works but save doesn't RRS feed

  • Question

  • User1316454812 posted

    Hi!

    I'm trying to map to database one object of type Offence. Objects contains other objects of type OffenceStatus and OffenceType. This object are already in the database, user can't add new ones, so I don't need to save them. When I manually insert some data into Offence table and try to get it in application, it works fine. But when I try to save new object type offence it says that it can't insert null into column OffenceStatusId. I checked and OffenceStatus is not null.

    I have the following code

    Code:
      public OffenceMap()
            {
            Not.LazyLoad();
                Table("Offence");
                Id(x => x.OffenceId).GeneratedBy.Identity();
                Map(x => x.EquipmentId).Nullable().Length(50);
               [b] References(x => x.OffenceStatus, "OffenceStatusId").PropertyRef("OffenceStatusId");
                References(x => x.OffenceType, "OffenceTypeId");[/b]
                Map(x => x.OffenceDate).CustomSqlType("DateTime").Not.Nullable();
                Map(x => x.OffenceTime).CustomSqlType("DateTime").Not.Nullable();
                References(x => x.Vehicle, "VehicleLicensePlateNumber");
                Map(x => x.IsArchived);
               Map(x => x.MarkedForPrinting, "IsMarkedForPrinting");
            }

    public void AddOffence(DateTime ofdate, DateTime oftime, string eqid, string licplatenum, int offtype)
            {
               
                OffenceTypeRepository otr = OffenceTypeRepository.GetInstance();
                OffenceType ot = otr.GetOffenceTypeById(offtype);

                OffenceStatusRepository osr = OffenceStatusRepository.GetInstance();
                OffenceStatus os = osr.GetOffenceStatusById((int)OffenceStatusName.New);

             
                Vehicle veh = VehicleRepository.GetInstance().GetVehicleByLicensePlateNum(licplatenum);

                Offence newOffence = new Offence(ot, ofdate, oftime, veh, os,eqid);
                try
                {
                    _NHibernateOffenceRep.Save(newOffence);
                    _NHibernateOffenceRep.Commit();
                    _AllOffences.Add(newOffence);
                }
                catch
                {
                    _NHibernateOffenceRep.HandleError();
                }
            }



    I tried everything i could think of. Please help!
    Thanks!

    Sunday, June 6, 2010 10:58 AM

All replies