public static List<Country> findList(string @where, params object[] @params) { CountryDBMapper dbm = new CountryDBMapper(); return dbm.findList(@where, @params); }
/// <summary> /// Convinience method to save a Country Object. /// Important note: DO NOT CALL THIS IN A LOOP! /// </summary> /// <param name="CountryObj"></param> /// <remarks> /// Important note: DO NOT CALL THIS IN A LOOP! /// This method simply instantiates a CountryDBMapper and calls the save method /// </remarks> public static void saveCountry(params Country[] CountryObj) { CountryDBMapper dbm = new CountryDBMapper(); dbm.saveList(CountryObj.ToList()); }
public static void deleteCountry(Country CountryObj) { CountryDBMapper dbm = new CountryDBMapper(); dbm.delete(CountryObj); }
public static List<Country> findList(string @where, List<IDataParameter> listOfIParams) { CountryDBMapper dbm = new CountryDBMapper(); return dbm.findList(@where,listOfIParams); }
public static Country findOne(string @where, params object[] @params) { CountryDBMapper dbm = new CountryDBMapper(); return (Country)dbm.findWhere(@where, @params); }
public void TestLoadAndSaveCountry() { ModelContext.beginTrans(); try { OracleMappers.CountryDBMapper pdb = new OracleMappers.CountryDBMapper(); 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 Country in database, table is empty"); } else { /** using (DataContext ctx = DBUtils.Current().dbContext()) { var query = ctx.ExecuteQuery<Country>(@"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); Country p = pdb.findByKey(pid); Country p2 = (Country)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.PrCountryId==p2.PrCountryId,"Expected Field CountryId to be equal"); Assert.IsTrue(p.PrCountryName==p2.PrCountryName,"Expected Field CountryName to be equal"); Assert.IsTrue(p.PrRegionId.GetValueOrDefault() ==p2.PrRegionId.GetValueOrDefault(),"Expected Field RegionId to be equal"); Assert.IsTrue(p.PrSkipField==p2.PrSkipField,"Expected Field SkipField to be equal"); Assert.IsTrue(p.PrLongFld.GetValueOrDefault() ==p2.PrLongFld.GetValueOrDefault(),"Expected Field LongFld to be equal"); Assert.IsTrue(p.PrLongFld2.GetValueOrDefault() ==p2.PrLongFld2.GetValueOrDefault(),"Expected Field LongFld2 to be equal"); p.isDirty = true; //to force save ModelContext.Current.saveModelObject(p); p = ModelContext.Current.loadModelObject< Country >(p.Id); p.loadObjectHierarchy(); string json = JsonConvert.SerializeObject(p,Formatting.Indented, new JsonSerializerSettings(){ ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); System.IO.FileInfo jf = new System.IO.FileInfo(".\\Country.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 TestLoadAndSaveCountry() { ModelContext.beginTrans(); try { OracleMappers.CountryDBMapper pdb = new OracleMappers.CountryDBMapper(); 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 Country in database, table is empty"); } else { /** * using (DataContext ctx = DBUtils.Current().dbContext()) { * * var query = ctx.ExecuteQuery<Country>(@"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); Country p = pdb.findByKey(pid); Country p2 = (Country)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.PrCountryId == p2.PrCountryId, "Expected Field CountryId to be equal"); Assert.IsTrue(p.PrCountryName == p2.PrCountryName, "Expected Field CountryName to be equal"); Assert.IsTrue(p.PrRegionId.GetValueOrDefault() == p2.PrRegionId.GetValueOrDefault(), "Expected Field RegionId to be equal"); Assert.IsTrue(p.PrSkipField == p2.PrSkipField, "Expected Field SkipField to be equal"); Assert.IsTrue(p.PrLongFld.GetValueOrDefault() == p2.PrLongFld.GetValueOrDefault(), "Expected Field LongFld to be equal"); Assert.IsTrue(p.PrLongFld2.GetValueOrDefault() == p2.PrLongFld2.GetValueOrDefault(), "Expected Field LongFld2 to be equal"); p.isDirty = true; //to force save ModelContext.Current.saveModelObject(p); p = ModelContext.Current.loadModelObject <Country>(p.Id); p.loadObjectHierarchy(); string json = JsonConvert.SerializeObject(p, Formatting.Indented, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); System.IO.FileInfo jf = new System.IO.FileInfo(".\\Country.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! } }
public static Country findOne(string @where, params object[] @params) { CountryDBMapper dbm = new CountryDBMapper(); return((Country)dbm.findWhere(@where, @params)); }
public static List <Country> findList(string @where, List <IDataParameter> listOfIParams) { CountryDBMapper dbm = new CountryDBMapper(); return(dbm.findList(@where, listOfIParams)); }
public static List <Country> findList(string @where, params object[] @params) { CountryDBMapper dbm = new CountryDBMapper(); return(dbm.findList(@where, @params)); }