public static void saveAccountBankInfo(DataTable dt, ref AccountBankInfo mo) { foreach (DataRow dr in dt.Rows) { saveAccountBankInfo(dr, ref mo); } }
public override IDbCommand getUpdateDBCommand(IModelObject modelObj, string sql) { AccountBankInfo obj = (AccountBankInfo)modelObj; IDbCommand stmt = this.dbConn.getCommand(sql); stmt.Parameters.Add(this.dbConn.getParameter(AccountBankInfo.STR_FLD_CONTACTNAME, obj.PrContactName)); stmt.Parameters.Add(this.dbConn.getParameter(AccountBankInfo.STR_FLD_CONTACTPHONE, obj.PrContactPhone)); stmt.Parameters.Add(this.dbConn.getParameter(AccountBankInfo.STR_FLD_CONTACTFAX, obj.PrContactFax)); stmt.Parameters.Add(this.dbConn.getParameter(AccountBankInfo.STR_FLD_ACCOUNTID, obj.PrAccountID)); stmt.Parameters.Add(this.dbConn.getParameter(AccountBankInfo.STR_FLD_SIGNEEEMPLOYEE, obj.PrSigneeEmployee)); stmt.Parameters.Add(this.dbConn.getParameter(AccountBankInfo.STR_FLD_COMPANYNAME, obj.PrCompanyName)); stmt.Parameters.Add(this.dbConn.getParameter(AccountBankInfo.STR_FLD_COMPANYBANKCODE, obj.PrCompanyBankCode)); stmt.Parameters.Add(this.dbConn.getParameter(AccountBankInfo.STR_FLD_BANKID, obj.PrBankId)); stmt.Parameters.Add(this.dbConn.getParameter(AccountBankInfo.STR_FLD_COOPCODE, obj.PrCOOPCode)); stmt.Parameters.Add(this.dbConn.getParameter(AccountBankInfo.STR_FLD_CREATEDATE, obj.CreateDate)); stmt.Parameters.Add(this.dbConn.getParameter(AccountBankInfo.STR_FLD_UPDATEDATE, obj.UpdateDate)); stmt.Parameters.Add(this.dbConn.getParameter(AccountBankInfo.STR_FLD_UPDATEUSER, obj.UpdateUser)); stmt.Parameters.Add(this.dbConn.getParameter(AccountBankInfo.STR_FLD_CREATEUSER, obj.CreateUser)); if (obj.isNew) { } else { //only add primary key if we are updating and as the last parameter stmt.Parameters.Add(this.dbConn.getParameter(AccountBankInfo.STR_FLD_ACCINFOID, obj.PrAccInfoId)); } return(stmt); }
public static AccountBankInfo loadFromDataRow(DataRow r) { DataRowLoader a = new DataRowLoader(); IModelObject mo = new AccountBankInfo(); a.DataSource = r; a.load(mo); return((AccountBankInfo)mo); }
/// <summary> /// Reload the AccountBankInfo from the database /// </summary> /// <remarks> /// use this method when you want to relad the AccountBankInfo /// from the database, discarding any changes /// </remarks> public static void reload(ref AccountBankInfo mo) { if (mo == null) { throw new System.ArgumentNullException("null object past to reload function"); } mo = (AccountBankInfo) new AccountBankInfoDBMapper().findByKey(mo.Id); }
public override void saveParents(IModelObject mo) { AccountBankInfo thisMo = ( AccountBankInfo)mo; //**** Parent Association:bank if ((thisMo.PrBank != null) && (thisMo.PrBank.NeedsSave)) { CsModelMappers.BankDBMapper mappervar = new CsModelMappers.BankDBMapper(this.dbConn); mappervar.save(thisMo.PrBank); thisMo.PrBankId = thisMo.PrBank.PrBANKID; } }
public static void saveAccountBankInfo(DataRow dr, ref AccountBankInfo mo) { if (mo == null) { mo = new AccountBankInfo(); } foreach (DataColumn dc in dr.Table.Columns) { mo.setAttribute(dc.ColumnName, dr[dc.ColumnName]); } saveAccountBankInfo(mo); }
public async Task LinkBankInfo(Account newaccount, BankInfo newbankInfo) { Account account1 = await ctx.accounts.FirstAsync(s => s.username.Equals(newaccount.username)); BankInfo bankInfo1 = await ctx.bankInfos.FirstAsync(c => c.cardNumber == newbankInfo.cardNumber); AccountBankInfo sc2 = new AccountBankInfo() { account = account1, bankInfo = bankInfo1 }; if (account1.AccountBankInfos == null) { account1.AccountBankInfos = new List <AccountBankInfo>(); } account1.AccountBankInfos.Add(sc2); ctx.Update(account1); await ctx.SaveChangesAsync(); }
public void saveAccountBankInfo(AccountBankInfo mo) { base.save(mo); }
public static void deleteAccountBankInfo(AccountBankInfo AccountBankInfoObj) { AccountBankInfoDBMapper dbm = new AccountBankInfoDBMapper(); dbm.delete(AccountBankInfoObj); }
public static void deleteAccountBankInfo(AccountBankInfo AccountBankInfoObj) { AccountBankInfoDBMapper dbm = new AccountBankInfoDBMapper(); dbm.delete(AccountBankInfoObj); }
private static async Task Seed(DatabaseContext databaseContext) { Console.WriteLine("Start of seed"); Address[] addresses = { new Address { street = "Solvgade 1, 3tv", city = "Horsens", zipCode = 8700, }, }; foreach (var address in addresses) { databaseContext.addresses.Add(address); } Console.WriteLine("2"); BankInfo[] bankInfos = { new BankInfo { cardNumber = 1234123412341234, cardHolder = "Pawel Skrzypkowski" }, }; foreach (var bankInfo in bankInfos) { databaseContext.bankInfos.Add(bankInfo); } Console.WriteLine("3"); Account[] acs = { new Account { username = "******", password = "******", email = "*****@*****.**", }, }; foreach (var account in acs) { databaseContext.accounts.Add(account); } Console.WriteLine("4"); Category[] categories = { new Category() { categoryName = "Italian", }, new Category() { categoryName = "Greek", }, }; foreach (var cat in categories) { databaseContext.categories.Add(cat); } Console.WriteLine("5"); Recipe[] recipes = { new Recipe() { recipeName = "Arrabbiata", recipeId = 1, description = "Arrabbiata sauce, or sugo all'arrabbiata in Italian, is a spicy sauce for pasta made from garlic, tomatoes, and dried red chili peppers cooked in olive oil. The sauce originates from the Lazio region, around Rome. Arrabbiata literally means 'angry' in Italian; the name of the sauce refers to the spiciness of the chili peppers.", instructions = "Sauté the crushed red pepper flakes: Heat the butter (or olive oil) in a large saucepan or deep sauté pan. Add the crushed red pepper flakes and sauté for about 2 minutes, to help toast and bring out their flavor.\nAdd onion and garlic: Add in the onions and sauté until softened, followed by the garlic.\nAdd tomatoes: Then add in the cans of whole tomatoes, juices included. And as they begin to heat up, use a wooden spoon or a potato masher to carefully break up the tomatoes. (Just wear an apron so that those juices inside of the tomatoes don’t accidentally splatter you!)\nSimmer: Continue heating the sauce until it comes to a simmer. Then reduce heat to medium (or medium-low) to maintain a low simmer, and let the sauce cook for about 30 minutes, or until it reaches your desired consistency.\nStir in the basil, salt and pepper. Then taste the sauce, and season with any extra salt, pepper and/or crushed red pepper flakes as needed.\nServe warm. Or let the sauce cool and then refrigerate it in a sealed container for up to 4 days.", cookingTime = 40, imageName = "Arrabiata.jpg" }, new Recipe() { recipeName = "Pizza", recipeId = 2, description = "Pizza, dish of Italian origin consisting of a flattened disk of bread dough topped with some combination of olive oil, oregano, tomato, olives, mozzarella or other cheese, and many other ingredients, baked quickly—usually, in a commercial setting, using a wood-fired oven heated to a very high temperature—and served hot.", instructions = "Add warm water to the bowl of a stand mixer with the dough attachment, and sprinkle the yeast on top of the water. Give the yeast a quick stir to mix it in with the water. Then let it sit for 5-10 minute until the yeast is foamy.\nTurn the mixer onto low speed, and add gradually flour, honey, olive oil and salt. Increase speed to medium-low, and continue mixing the dough for 5 minutes.\nRemove dough from the mixing bowl, and use your hands to shape it into a ball. Grease the mixing bowl (or a separate bowl) with olive oil or cooking spray, then place the dough ball back in the bowl and cover it with a damp towel. Place in a warm location (I set mine by the window) and let it rise for 30-45 minutes until the dough has nearly doubled in size.\nPreheat oven to 450 degrees F. Turn the dough onto a floured surface, and roll the dough into a 12- to 14-inch round for a thick-crusted pizza. (Or cut the dough in half, and roll it into two 12-inch rounds for two thin crust pizzas.) Sprinkle a baking sheet or pizza stone evenly with the cornmeal, then place the dough on the baking sheet.\nTop the dough with your desired sauce and toppings. (And for extra-golden crust, brush the crust with an extra few teaspoons of olive oil or butter.)\nFor thick crust, bake for 16-18 minutes, or until the crust is golden brown and the toppings are melted and cooked. For the (two) thin crusts, bake for 14-16 minutes, or until the crust is golden brown and the toppings are melted and cooked.\nSlice and serve pizza warm.", cookingTime = 75, imageName = "Pizza.jpeg" }, }; foreach (var rec in recipes) { databaseContext.recipes.Add(rec); } Console.WriteLine("6"); Ingredient[] ingredients = { new Ingredient() { ingredientId = 1, ingredientName = "Garlic", number = 3, unitType = "cloves" }, new Ingredient() { ingredientId = 2, ingredientName = "Pasta", number = 0.5, unitType = "kg" } }; foreach (var ing in ingredients) { databaseContext.ingredients.Add(ing); } Console.WriteLine("8"); databaseContext.SaveChanges(); Shop[] shops = { new Shop { shopId = 1, shopName = "Lidl", shopAddress = addresses[0] }, }; foreach (var shop in shops) { databaseContext.shops.Add(shop); } Console.WriteLine("9"); ShopIngredient[] shopIngredients = { new ShopIngredient() { id = 1, name = "Garlic", price = 3, amount = 3, unitType = "cloves" }, new ShopIngredient() { id = 2, name = "Pasta", price = 2, amount = 0.2, unitType = "kg" }, }; foreach (var shoping in shopIngredients) { databaseContext.shopIngredients.Add(shoping); } Console.WriteLine("10"); databaseContext.SaveChanges(); Account steve = await databaseContext.accounts.FirstAsync(s => s.username.Equals("Jannik")); Address tek = await databaseContext.addresses.FirstAsync(c => c.street.Equals("Solvgade 1, 3tv")); AccountAddress sc = new AccountAddress() { address = tek, account = steve }; steve.AccountAddresses = new List <AccountAddress>(); steve.AccountAddresses.Add(sc); databaseContext.Update(steve); // ctx.Set<StudentCourse>().Add(sc); This is an alternative await databaseContext.SaveChangesAsync(); Account steve2 = await databaseContext.accounts.FirstAsync(s => s.username.Equals("Jannik")); BankInfo bankInfo2 = await databaseContext.bankInfos.FirstAsync(c => c.cardNumber == 1234123412341234); AccountBankInfo sc2 = new AccountBankInfo() { account = steve2, bankInfo = bankInfo2 }; steve.AccountBankInfos = new List <AccountBankInfo>(); steve.AccountBankInfos.Add(sc2); databaseContext.Update(steve2); // ctx.Set<StudentCourse>().Add(sc); This is an alternative await databaseContext.SaveChangesAsync(); //Connecting ingredients with recipes Recipe steve1 = await databaseContext.recipes.FirstAsync(s => s.recipeId == 1); Ingredient tek1 = await databaseContext.ingredients.FirstAsync(c => c.ingredientId == 1); IngredientRecipe sc1 = new IngredientRecipe() { ingredient = tek1, recipe = steve1 }; steve1.IngredientRecipes = new List <IngredientRecipe>(); steve1.IngredientRecipes.Add(sc1); databaseContext.Update(steve1); // ctx.Set<StudentCourse>().Add(sc); This is an alternative await databaseContext.SaveChangesAsync(); Recipe steve3 = await databaseContext.recipes.FirstAsync(s => s.recipeId == 1); Category bankInfo3 = await databaseContext.categories.FirstAsync(c => c.categoryName.Equals("Italian")); RecipeCategory sc3 = new RecipeCategory() { recipe = steve3, category = bankInfo3 }; steve3.RecipeCategories = new List <RecipeCategory>(); steve3.RecipeCategories.Add(sc3); databaseContext.Update(steve3); // ctx.Set<StudentCourse>().Add(sc); This is an alternative await databaseContext.SaveChangesAsync(); //connecting second recipe Recipe steve5 = await databaseContext.recipes.FirstAsync(s => s.recipeId == 2); Ingredient tek5 = await databaseContext.ingredients.FirstAsync(c => c.ingredientId == 1); IngredientRecipe sc5 = new IngredientRecipe() { ingredient = tek5, recipe = steve5 }; steve5.IngredientRecipes = new List <IngredientRecipe>(); steve5.IngredientRecipes.Add(sc5); databaseContext.Update(steve5); // ctx.Set<StudentCourse>().Add(sc); This is an alternative await databaseContext.SaveChangesAsync(); //adding second ingredient Recipe steve7 = await databaseContext.recipes.FirstAsync(s => s.recipeId == 2); Ingredient tek7 = await databaseContext.ingredients.FirstAsync(c => c.ingredientId == 2); IngredientRecipe sc7 = new IngredientRecipe() { ingredient = tek7, recipe = steve7 }; if (steve7.IngredientRecipes == null) { steve7.IngredientRecipes = new List <IngredientRecipe>(); } steve7.IngredientRecipes.Add(sc7); databaseContext.Update(steve7); // ctx.Set<StudentCourse>().Add(sc); This is an alternative await databaseContext.SaveChangesAsync(); Recipe steve6 = await databaseContext.recipes.FirstAsync(s => s.recipeId == 2); Category bankInfo6 = await databaseContext.categories.FirstAsync(c => c.categoryName.Equals("Greek")); RecipeCategory sc6 = new RecipeCategory() { recipe = steve6, category = bankInfo6 }; steve6.RecipeCategories = new List <RecipeCategory>(); steve6.RecipeCategories.Add(sc6); databaseContext.Update(steve6); // ctx.Set<StudentCourse>().Add(sc); This is an alternative await databaseContext.SaveChangesAsync(); //shops //adding shopingredients Shop shop1 = await databaseContext.shops.FirstAsync(s => s.shopId == 1); ShopIngredient shopIngredient1 = await databaseContext.shopIngredients.FirstAsync(c => c.id == 1); ShopVare ss1 = new ShopVare() { shop = shop1, shopIngredient = shopIngredient1 }; if (shop1.shopVares == null) { shop1.shopVares = new List <ShopVare>(); } shop1.shopVares.Add(ss1); databaseContext.Update(shop1); // ctx.Set<StudentCourse>().Add(sc); This is an alternative await databaseContext.SaveChangesAsync(); Shop shop2 = await databaseContext.shops.FirstAsync(s => s.shopId == 1); ShopIngredient shopIngredient2 = await databaseContext.shopIngredients.FirstAsync(c => c.id == 2); ShopVare ss2 = new ShopVare() { shop = shop2, shopIngredient = shopIngredient2 }; if (shop2.shopVares == null) { shop2.shopVares = new List <ShopVare>(); } shop2.shopVares.Add(ss2); databaseContext.Update(shop2); // ctx.Set<StudentCourse>().Add(sc); This is an alternative await databaseContext.SaveChangesAsync(); //update categories in recipes Recipe recipeUp1 = recipes[0]; Recipe recipeUp2 = recipes[1]; List <Category> categoriesUp = await databaseContext.categories.ToListAsync(); recipeUp1.category = categoriesUp[0]; recipeUp2.category = categoriesUp[1]; databaseContext.recipes.Update(recipeUp1); databaseContext.recipes.Update(recipeUp2); await databaseContext.SaveChangesAsync(); Console.WriteLine("Finished seeding"); }
public void saveAccountBankInfo(AccountBankInfo mo) { base.save(mo); }
public static void saveAccountBankInfo(DataTable dt, ref AccountBankInfo mo) { foreach (DataRow dr in dt.Rows) { saveAccountBankInfo(dr, ref mo); } }
public static void saveAccountBankInfo(DataRow dr, ref AccountBankInfo mo) { if (mo == null) { mo = new AccountBankInfo(); } foreach (DataColumn dc in dr.Table.Columns) { mo.setAttribute(dc.ColumnName, dr[dc.ColumnName]); } saveAccountBankInfo(mo); }
/// <summary> /// Reload the AccountBankInfo from the database /// </summary> /// <remarks> /// use this method when you want to relad the AccountBankInfo /// from the database, discarding any changes /// </remarks> public static void reload(ref AccountBankInfo mo) { if (mo == null) { throw new System.ArgumentNullException("null object past to reload function"); } mo = (AccountBankInfo)new AccountBankInfoDBMapper().findByKey(mo.Id); }
public static AccountBankInfo loadFromDataRow(DataRow r) { DataRowLoader a = new DataRowLoader(); IModelObject mo = new AccountBankInfo(); a.DataSource = r; a.load(mo); return (AccountBankInfo)mo; }
public override void load(IModelObject mo) { const int DATAREADER_FLD_ACCINFOID = 0; const int DATAREADER_FLD_CONTACTNAME = 1; const int DATAREADER_FLD_CONTACTPHONE = 2; const int DATAREADER_FLD_CONTACTFAX = 3; const int DATAREADER_FLD_ACCOUNTID = 4; const int DATAREADER_FLD_SIGNEEEMPLOYEE = 5; const int DATAREADER_FLD_COMPANYNAME = 6; const int DATAREADER_FLD_COMPANYBANKCODE = 7; const int DATAREADER_FLD_BANKID = 8; const int DATAREADER_FLD_COOPCODE = 9; const int DATAREADER_FLD_CREATEDATE = 10; const int DATAREADER_FLD_UPDATEDATE = 11; const int DATAREADER_FLD_UPDATEUSER = 12; const int DATAREADER_FLD_CREATEUSER = 13; AccountBankInfo obj = (AccountBankInfo)mo; obj.IsObjectLoading = true; if (!this.reader.IsDBNull(DATAREADER_FLD_ACCINFOID)) { obj.PrAccInfoId = Convert.ToInt64(this.reader.GetInt32(DATAREADER_FLD_ACCINFOID)); } if (!this.reader.IsDBNull(DATAREADER_FLD_CONTACTNAME)) { obj.PrContactName = this.reader.GetString(DATAREADER_FLD_CONTACTNAME); } if (!this.reader.IsDBNull(DATAREADER_FLD_CONTACTPHONE)) { obj.PrContactPhone = this.reader.GetString(DATAREADER_FLD_CONTACTPHONE); } if (!this.reader.IsDBNull(DATAREADER_FLD_CONTACTFAX)) { obj.PrContactFax = this.reader.GetString(DATAREADER_FLD_CONTACTFAX); } if (!this.reader.IsDBNull(DATAREADER_FLD_ACCOUNTID)) { obj.PrAccountID = Convert.ToInt64(this.reader.GetInt32(DATAREADER_FLD_ACCOUNTID)); } if (!this.reader.IsDBNull(DATAREADER_FLD_SIGNEEEMPLOYEE)) { obj.PrSigneeEmployee = this.reader.GetString(DATAREADER_FLD_SIGNEEEMPLOYEE); } if (!this.reader.IsDBNull(DATAREADER_FLD_COMPANYNAME)) { obj.PrCompanyName = this.reader.GetString(DATAREADER_FLD_COMPANYNAME); } if (!this.reader.IsDBNull(DATAREADER_FLD_COMPANYBANKCODE)) { obj.PrCompanyBankCode = this.reader.GetString(DATAREADER_FLD_COMPANYBANKCODE); } if (!this.reader.IsDBNull(DATAREADER_FLD_BANKID)) { obj.PrBankId = Convert.ToInt64(this.reader.GetInt32(DATAREADER_FLD_BANKID)); } if (!this.reader.IsDBNull(DATAREADER_FLD_COOPCODE)) { obj.PrCOOPCode = this.reader.GetString(DATAREADER_FLD_COOPCODE); } if (!this.reader.IsDBNull(DATAREADER_FLD_CREATEDATE)) { obj.CreateDate = this.reader.GetDateTime(DATAREADER_FLD_CREATEDATE); } if (!this.reader.IsDBNull(DATAREADER_FLD_UPDATEDATE)) { obj.UpdateDate = this.reader.GetDateTime(DATAREADER_FLD_UPDATEDATE); } if (!this.reader.IsDBNull(DATAREADER_FLD_UPDATEUSER)) { obj.UpdateUser = this.reader.GetString(DATAREADER_FLD_UPDATEUSER); } if (!this.reader.IsDBNull(DATAREADER_FLD_CREATEUSER)) { obj.CreateUser = this.reader.GetString(DATAREADER_FLD_CREATEUSER); } obj.isNew = false; // since we've just loaded from database, we mark as "old" obj.isDirty = false; obj.IsObjectLoading = false; obj.afterLoad(); return; }
[TestMethod()] public void TestLoadAndSaveAccountBankInfo() { ModelContext.beginTrans(); try { CsModelMappers.AccountBankInfoDBMapper pdb = new CsModelMappers.AccountBankInfoDBMapper(); 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 AccountBankInfo in database, table is empty"); } else { /** * using (DataContext ctx = DBUtils.Current().dbContext()) { * * var query = ctx.ExecuteQuery<AccountBankInfo>(@"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); AccountBankInfo p = pdb.findByKey(pid); AccountBankInfo p2 = (AccountBankInfo)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.PrAccInfoId == p2.PrAccInfoId, "Expected Field AccInfoId to be equal"); Assert.IsTrue(p.PrContactName == p2.PrContactName, "Expected Field ContactName to be equal"); Assert.IsTrue(p.PrContactPhone == p2.PrContactPhone, "Expected Field ContactPhone to be equal"); Assert.IsTrue(p.PrContactFax == p2.PrContactFax, "Expected Field ContactFax to be equal"); Assert.IsTrue(p.PrAccountID.GetValueOrDefault() == p2.PrAccountID.GetValueOrDefault(), "Expected Field AccountID to be equal"); Assert.IsTrue(p.PrSigneeEmployee == p2.PrSigneeEmployee, "Expected Field SigneeEmployee to be equal"); Assert.IsTrue(p.PrCompanyName == p2.PrCompanyName, "Expected Field CompanyName to be equal"); Assert.IsTrue(p.PrCompanyBankCode == p2.PrCompanyBankCode, "Expected Field CompanyBankCode to be equal"); Assert.IsTrue(p.PrBankId.GetValueOrDefault() == p2.PrBankId.GetValueOrDefault(), "Expected Field BankId to be equal"); Assert.IsTrue(p.PrCOOPCode == p2.PrCOOPCode, "Expected Field COOPCode 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"); //skip update user! Assert.IsTrue(p.CreateUser == p2.CreateUser, "Expected Field Createuser to be equal"); p.isDirty = true; //to force save ModelContext.Current.saveModelObject(p); p = ModelContext.Current.loadModelObject <AccountBankInfo>(p.Id); p.loadObjectHierarchy(); string json = JsonConvert.SerializeObject(p, Formatting.Indented, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); System.IO.FileInfo jf = new System.IO.FileInfo(".\\AccountBankInfo.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! } }