public static int InsertLocation(Location loc) { var count = 0; using (var ctx = new FRESContext()) { ctx.Location.Add(loc); count = ctx.SaveChanges(); if (count == 0) throw new Exception("Row affected is 0"); } return count; }
public static int UpdateRealEstateT_Location(RealEstateT res) { var count = 0; using (var ctx = new FRESContext()) { var org = ctx.RealEstateT.Find(res.RealEstateTId); if (org != null) { ctx.Entry(org).CurrentValues.SetValues(res); count = ctx.SaveChanges(); } } return count; }
public static int UpdateRealEstateE(RealEstateE res) { var count = 0; using (var ctx = new FRESContext()) { ctx.RealEstateE.Attach(res); var entry = ctx.Entry(res); entry.Property(e => e.Data).IsModified = true; entry.Property(e => e.State).IsModified = true; ctx.SaveChanges(); } return count; }
public static int MigrateAddress() { var count = 0; using (var ctx = new FRESContext()) { var items = ctx.Address_bak.ToList(); //foreach (var item in items) items.AsParallel().WithDegreeOfParallelism(1).ForAll(item => { try { var villages = item.VillageName.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); foreach (var village in villages) { ctx.Address.Add(new Address() { District = item.District.Trim(), Province = item.Province.Trim(), SubDistrict = item.SubDistrict.Trim(), VillageName = village.Trim(), VillageNo = item.VillageNo.Trim() }); Console.WriteLine(item.Province + " " + item.District + " " + item.SubDistrict + " " + item.VillageNo + " " + village); } } catch (Exception ex) { Console.WriteLine(ex.Message); Console.ReadKey(); } } ); ctx.SaveChanges(); } return count; }
public static int InsertRealEstateT(List<RealEstateT> res) { var count = 0; using (var ctx = new FRESContext()) { ctx.RealEstateT.AddRange(res); count = ctx.SaveChanges(); if (res.Count != count) throw new Exception("Row affected is " + count + ", expect " + res.Count); } return count; }
public static int InsertRealEstateT(RealEstateT res) { var count = 0; using (var ctx = new FRESContext()) { ctx.RealEstateT.Add(res); count = ctx.SaveChanges(); if (count == 0) throw new Exception("Row affected is 0"); } return count; }