/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { var hashCode = 41; // Suitable nullity checks etc, of course :) if (EmploymentStatus != null) { hashCode = hashCode * 59 + EmploymentStatus.GetHashCode(); } if (EmployeeType != null) { hashCode = hashCode * 59 + EmployeeType.GetHashCode(); } if (HireDetails != null) { hashCode = hashCode * 59 + HireDetails.GetHashCode(); } if (DateJoinedNHS != null) { hashCode = hashCode * 59 + DateJoinedNHS.GetHashCode(); } if (AlAccrualPlan != null) { hashCode = hashCode * 59 + AlAccrualPlan.GetHashCode(); } if (PrevEmployer != null) { hashCode = hashCode * 59 + PrevEmployer.GetHashCode(); } if (Agencies != null) { hashCode = hashCode * 59 + Agencies.GetHashCode(); } return(hashCode); } }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { var hashCode = 41; // Suitable nullity checks etc, of course :) hashCode = hashCode * 59 + Id.GetHashCode(); if (When != null) { hashCode = hashCode * 59 + When.GetHashCode(); } if (Actual != null) { hashCode = hashCode * 59 + Actual.GetHashCode(); } hashCode = hashCode * 59 + WorkTime.GetHashCode(); hashCode = hashCode * 59 + ContractedTime.GetHashCode(); hashCode = hashCode * 59 + PayState.GetHashCode(); if (EmployeeType != null) { hashCode = hashCode * 59 + EmployeeType.GetHashCode(); } if (Person != null) { hashCode = hashCode * 59 + Person.GetHashCode(); } if (Assignment != null) { hashCode = hashCode * 59 + Assignment.GetHashCode(); } if (Post != null) { hashCode = hashCode * 59 + Post.GetHashCode(); } if (Posting != null) { hashCode = hashCode * 59 + Posting.GetHashCode(); } if (Cancellation != null) { hashCode = hashCode * 59 + Cancellation.GetHashCode(); } hashCode = hashCode * 59 + InCharge.GetHashCode(); if (Shift != null) { hashCode = hashCode * 59 + Shift.GetHashCode(); } if (Duty != null) { hashCode = hashCode * 59 + Duty.GetHashCode(); } if (Fulfillment != null) { hashCode = hashCode * 59 + Fulfillment.GetHashCode(); } if (CostCentre != null) { hashCode = hashCode * 59 + CostCentre.GetHashCode(); } if (OwningUnit != null) { hashCode = hashCode * 59 + OwningUnit.GetHashCode(); } if (ResourcingUnit != null) { hashCode = hashCode * 59 + ResourcingUnit.GetHashCode(); } if (Requirement != null) { hashCode = hashCode * 59 + Requirement.GetHashCode(); } if (Location != null) { hashCode = hashCode * 59 + Location.GetHashCode(); } if (AdditionalDutyReason != null) { hashCode = hashCode * 59 + AdditionalDutyReason.GetHashCode(); } hashCode = hashCode * 59 + DutyHasWarnings.GetHashCode(); return(hashCode); } }
[TestMethod()] public void TestLoadAndSaveEmployeeType() { ModelContext.beginTrans(); try { CsModelMappers.EmployeeTypeDBMapper pdb = new CsModelMappers.EmployeeTypeDBMapper(); long count = pdb.RecordCount(); if (pdb.SelectFromObjectName != pdb.ManagedTableName) { long countFromSelectObject = pdb.dbConn.getLngValue("select count(*) from " + pdb.SelectFromObjectName); Assert.AreEqual(count, countFromSelectObject, "Count of records in managedTableName {0} and SelectFromObjectName {1} should be equal, as there needs to be exactly 1 to 1 match between records in managed table and selectFromObject.", pdb.ManagedTableName, pdb.SelectFromObjectName); } if (count == 0) { Assert.Inconclusive("No EmployeeType in database, table is empty"); } else { /** * using (DataContext ctx = DBUtils.Current().dbContext()) { * * var query = ctx.ExecuteQuery<EmployeeType>(@"SELECT * FROM " + pdb.SelectFromObjectName ).Skip(1).Take(1); * var lst = query.ToList(); * * Assert.AreEqual(lst.Count, 1, "Expected to receive 1 record, got: " + lst.Count); * * } * todo: fix boolean fields by generating properties of original fields **/ object pid = ModelContext.CurrentDBUtils.getObjectValue("select top 1 " + pdb.pkFieldName + " from " + pdb.ManagedTableName); EmployeeType p = pdb.findByKey(pid); EmployeeType p2 = (EmployeeType)p.copy(); //Test equality and hash codes Assert.AreEqual(p.GetHashCode(), p2.GetHashCode()); Assert.AreEqual(p, p2); p.isDirty = true; // force save pdb.save(p); // now reload object from database p = null; p = pdb.findByKey(pid); //test fields to be equal before and after save Assert.IsTrue(p.PrEmployeeTypeCode == p2.PrEmployeeTypeCode, "Expected Field EmployeeTypeCode to be equal"); Assert.IsTrue(p.PrEmployeeType == p2.PrEmployeeType, "Expected Field EmployeeType to be equal"); p.isDirty = true; //to force save ModelContext.Current.saveModelObject(p); p = ModelContext.Current.loadModelObject <EmployeeType>(p.Id); p.loadObjectHierarchy(); string json = JsonConvert.SerializeObject(p, Formatting.Indented, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); System.IO.FileInfo jf = new System.IO.FileInfo(".\\EmployeeType.json"); System.IO.File.WriteAllText(jf.FullName, json); if (pdb.isPrimaryKeyAutogenerated) { p.isNew = true; p.isDirty = true; try { pdb.save(p); } catch (System.Exception e) { Assert.IsTrue(e.Message.ToUpper().Contains("UNIQUE INDEX") || e.Message.Contains("Violation of UNIQUE KEY constraint"), "Insert statement produced error other than violation of unique key:" + e.Message); } } } } finally { ModelContext.rollbackTrans(); // 'Nothing should be saved to the database! } }