public static void deleteEmployee(Employee EmployeeObj) { EmployeeDBMapper dbm = new EmployeeDBMapper(); dbm.delete(EmployeeObj); }
public static Employee findOne(string @where, params object[] @params) { EmployeeDBMapper dbm = new EmployeeDBMapper(); return((Employee)dbm.findWhere(@where, @params)); }
/// <summary> /// Convinience method to save a Employee Object. /// Important note: DO NOT CALL THIS IN A LOOP! /// </summary> /// <param name="EmployeeObj"></param> /// <remarks> /// Important note: DO NOT CALL THIS IN A LOOP! /// This method simply instantiates a EmployeeDBMapper and calls the save method /// </remarks> public static void saveEmployee(params Employee[] EmployeeObj) { EmployeeDBMapper dbm = new EmployeeDBMapper(); dbm.saveList(EmployeeObj.ToList()); }
public static List <Employee> findList(string @where, params object[] @params) { EmployeeDBMapper dbm = new EmployeeDBMapper(); return(dbm.findList(@where, @params)); }
public static List <Employee> findList(string @where, List <IDataParameter> listOfIParams) { EmployeeDBMapper dbm = new EmployeeDBMapper(); return(dbm.findList(@where, listOfIParams)); }
public static Employee findOne(string @where, params object[] @params) { EmployeeDBMapper dbm = new EmployeeDBMapper(); return (Employee)dbm.findWhere(@where, @params); }
public static List<Employee> findList(string @where, List<IDataParameter> listOfIParams) { EmployeeDBMapper dbm = new EmployeeDBMapper(); return dbm.findList(@where,listOfIParams); }
public static List<Employee> findList(string @where, params object[] @params) { EmployeeDBMapper dbm = new EmployeeDBMapper(); return dbm.findList(@where, @params); }
public void TestLoadAndSaveEmployee() { ModelContext.beginTrans(); try { OracleMappers.EmployeeDBMapper pdb = new OracleMappers.EmployeeDBMapper(); 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 Employee in database, table is empty"); } else { /** using (DataContext ctx = DBUtils.Current().dbContext()) { var query = ctx.ExecuteQuery<Employee>(@"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); Employee p = pdb.findByKey(pid); Employee p2 = (Employee)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.PrEmployeeId==p2.PrEmployeeId,"Expected Field EmployeeId to be equal"); Assert.IsTrue(p.PrFirstName==p2.PrFirstName,"Expected Field FirstName to be equal"); Assert.IsTrue(p.PrLastName==p2.PrLastName,"Expected Field LastName to be equal"); Assert.IsTrue(p.PrEMAIL==p2.PrEMAIL,"Expected Field EMAIL to be equal"); Assert.IsTrue(p.PrPhoneNumber==p2.PrPhoneNumber,"Expected Field PhoneNumber to be equal"); Assert.IsTrue(p.PrHireDate.GetValueOrDefault() ==p2.PrHireDate.GetValueOrDefault(),"Expected Field HireDate to be equal"); Assert.IsTrue(p.PrJobId==p2.PrJobId,"Expected Field JobId to be equal"); Assert.IsTrue(p.PrSALARY.GetValueOrDefault() ==p2.PrSALARY.GetValueOrDefault(),"Expected Field SALARY to be equal"); Assert.IsTrue(p.PrCommissionPct.GetValueOrDefault() ==p2.PrCommissionPct.GetValueOrDefault(),"Expected Field CommissionPct to be equal"); Assert.IsTrue(p.PrManagerId.GetValueOrDefault() ==p2.PrManagerId.GetValueOrDefault(),"Expected Field ManagerId to be equal"); Assert.IsTrue(p.PrDepartmentId.GetValueOrDefault() ==p2.PrDepartmentId.GetValueOrDefault(),"Expected Field DepartmentId to be equal"); Assert.IsTrue(p.CreateDate.GetValueOrDefault().ToString("MM/dd/yy H:mm:ss zzz") ==p2.CreateDate.GetValueOrDefault().ToString("MM/dd/yy H:mm:ss zzz"),"Expected Field CreateDate to be equal"); Assert.IsFalse(p.UpdateDate.GetValueOrDefault() == p2.UpdateDate.GetValueOrDefault(),"Expected Field UpdateDate NOT to be equal"); Assert.IsTrue(p.CreateUser==p2.CreateUser,"Expected Field CreateUser to be equal"); //skip update user! Assert.IsTrue(p.PrLocationId.GetValueOrDefault() ==p2.PrLocationId.GetValueOrDefault(),"Expected Field LocationId to be equal"); Assert.IsTrue(p.PrCountryId==p2.PrCountryId,"Expected Field CountryId to be equal"); Assert.IsTrue(p.PrDepartmentName==p2.PrDepartmentName,"Expected Field DepartmentName to be equal"); Assert.IsTrue(p.PrJobTitle==p2.PrJobTitle,"Expected Field JobTitle to be equal"); Assert.IsTrue(p.PrCITY==p2.PrCITY,"Expected Field CITY to be equal"); Assert.IsTrue(p.PrStateProvince==p2.PrStateProvince,"Expected Field StateProvince to be equal"); Assert.IsTrue(p.PrCountryName==p2.PrCountryName,"Expected Field CountryName to be equal"); Assert.IsTrue(p.PrRegionName==p2.PrRegionName,"Expected Field RegionName to be equal"); Assert.IsTrue(p.PrManagerName==p2.PrManagerName,"Expected Field ManagerName to be equal"); Assert.IsTrue(p.PrJobHistory != null); Assert.IsTrue(p.PrCourses != null); Assert.IsTrue(p.PrTrainingHistory != null); p.isDirty = true; //to force save ModelContext.Current.saveModelObject(p); p = ModelContext.Current.loadModelObject< Employee >(p.Id); p.loadObjectHierarchy(); string json = JsonConvert.SerializeObject(p,Formatting.Indented, new JsonSerializerSettings(){ ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); System.IO.FileInfo jf = new System.IO.FileInfo(".\\Employee.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! } }
[TestMethod()] public void TestLoadAndSaveEmployee() { ModelContext.beginTrans(); try { OracleMappers.EmployeeDBMapper pdb = new OracleMappers.EmployeeDBMapper(); 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 Employee in database, table is empty"); } else { /** * using (DataContext ctx = DBUtils.Current().dbContext()) { * * var query = ctx.ExecuteQuery<Employee>(@"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); Employee p = pdb.findByKey(pid); Employee p2 = (Employee)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.PrEmployeeId == p2.PrEmployeeId, "Expected Field EmployeeId to be equal"); Assert.IsTrue(p.PrFirstName == p2.PrFirstName, "Expected Field FirstName to be equal"); Assert.IsTrue(p.PrLastName == p2.PrLastName, "Expected Field LastName to be equal"); Assert.IsTrue(p.PrEMAIL == p2.PrEMAIL, "Expected Field EMAIL to be equal"); Assert.IsTrue(p.PrPhoneNumber == p2.PrPhoneNumber, "Expected Field PhoneNumber to be equal"); Assert.IsTrue(p.PrHireDate.GetValueOrDefault() == p2.PrHireDate.GetValueOrDefault(), "Expected Field HireDate to be equal"); Assert.IsTrue(p.PrJobId == p2.PrJobId, "Expected Field JobId to be equal"); Assert.IsTrue(p.PrSALARY.GetValueOrDefault() == p2.PrSALARY.GetValueOrDefault(), "Expected Field SALARY to be equal"); Assert.IsTrue(p.PrCommissionPct.GetValueOrDefault() == p2.PrCommissionPct.GetValueOrDefault(), "Expected Field CommissionPct to be equal"); Assert.IsTrue(p.PrManagerId.GetValueOrDefault() == p2.PrManagerId.GetValueOrDefault(), "Expected Field ManagerId to be equal"); Assert.IsTrue(p.PrDepartmentId.GetValueOrDefault() == p2.PrDepartmentId.GetValueOrDefault(), "Expected Field DepartmentId to be equal"); Assert.IsTrue(p.CreateDate.GetValueOrDefault().ToString("MM/dd/yy H:mm:ss zzz") == p2.CreateDate.GetValueOrDefault().ToString("MM/dd/yy H:mm:ss zzz"), "Expected Field CreateDate to be equal"); Assert.IsFalse(p.UpdateDate.GetValueOrDefault() == p2.UpdateDate.GetValueOrDefault(), "Expected Field UpdateDate NOT to be equal"); Assert.IsTrue(p.CreateUser == p2.CreateUser, "Expected Field CreateUser to be equal"); //skip update user! Assert.IsTrue(p.PrLocationId.GetValueOrDefault() == p2.PrLocationId.GetValueOrDefault(), "Expected Field LocationId to be equal"); Assert.IsTrue(p.PrCountryId == p2.PrCountryId, "Expected Field CountryId to be equal"); Assert.IsTrue(p.PrDepartmentName == p2.PrDepartmentName, "Expected Field DepartmentName to be equal"); Assert.IsTrue(p.PrJobTitle == p2.PrJobTitle, "Expected Field JobTitle to be equal"); Assert.IsTrue(p.PrCITY == p2.PrCITY, "Expected Field CITY to be equal"); Assert.IsTrue(p.PrStateProvince == p2.PrStateProvince, "Expected Field StateProvince to be equal"); Assert.IsTrue(p.PrCountryName == p2.PrCountryName, "Expected Field CountryName to be equal"); Assert.IsTrue(p.PrRegionName == p2.PrRegionName, "Expected Field RegionName to be equal"); Assert.IsTrue(p.PrManagerName == p2.PrManagerName, "Expected Field ManagerName to be equal"); Assert.IsTrue(p.PrJobHistory != null); Assert.IsTrue(p.PrCourses != null); Assert.IsTrue(p.PrTrainingHistory != null); p.isDirty = true; //to force save ModelContext.Current.saveModelObject(p); p = ModelContext.Current.loadModelObject <Employee>(p.Id); p.loadObjectHierarchy(); string json = JsonConvert.SerializeObject(p, Formatting.Indented, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); System.IO.FileInfo jf = new System.IO.FileInfo(".\\Employee.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! } }