public bool Update(Core.Entities.Bank entity) { var ef = mapper.Map <Bank>(entity); using (FinanceEntities context = factory.CreateContext()) { context.Entry(ef).State = EntityState.Modified; context.SaveChanges(); } //read back columns which may have changed //entity.RecordUpdatedDateTime = ef.RecordUpdatedDateTime; return(true); }
public bool Delete(Core.Entities.BalanceDate entity) { var ef = mapper.Map <BalanceDate>(entity); //need to delete children to prevent EF FK error ef.BalanceDateBankAccounts.Clear(); using (FinanceEntities context = factory.CreateContext()) { context.Entry(ef).State = EntityState.Deleted; // deletes are cascaded to BalanceBankAccount context.SaveChanges(); } return(true); }
public bool Delete(List <int> ids) { using (FinanceEntities context = factory.CreateContext()) { foreach (var id in ids) { var ef = new BankAccount() { BankAccountId = id }; context.Entry(ef).State = EntityState.Deleted; } context.SaveChanges(); } return(true); }
public List <Core.Entities.DataIdName> ReadListDataIdName() { List <Core.Entities.DataIdName> list = null; using (FinanceEntities context = factory.CreateContext()) { var ef = (from b in context.BalanceDates select b).ToList(); list = mapper.Map <List <Core.Entities.DataIdName> >(ef); //list = (from b in context.BalanceDates // select b).Project(mapper).To<Core.Entities.DataIdName>().ToList(); } return(list); }
public int Add(Core.Entities.BankAccount entity) { int id = 0; var ef = mapper.Map <BankAccount>(entity); using (FinanceEntities context = factory.CreateContext()) { context.Entry(ef).State = EntityState.Added; context.SaveChanges(); } //read back columns which may have changed entity.BankAccountId = ef.BankAccountId; entity.RecordCreatedDateTime = ef.RecordCreatedDateTime; entity.RecordUpdatedDateTime = ef.RecordUpdatedDateTime; id = ef.BankAccountId; return(id); }
public List <Core.Entities.BalanceDate> ReadList() { List <Core.Entities.BalanceDate> list = null; using (FinanceEntities context = factory.CreateContext()) { var ef = ReadQuery(context).ToList(); //var ef = (from b in context.BalanceDates // .Include(a => a.BalanceDateBankAccounts) // .Include("BalanceDateBankAccounts.BankAccount") // .Include("BalanceDateBankAccounts.BankAccount.Bank") // select b).ToList(); list = mapper.Map <List <Core.Entities.BalanceDate> >(ef); } return(list); }
public List <Core.Entities.DataIdName> ReadListDataIdName() { List <Core.Entities.DataIdName> list = null; //try //{ using (FinanceEntities context = factory.CreateContext()) { list = (from b in context.Cashflows select b).Project(mapper).To <Core.Entities.DataIdName>().ToList(); } //} //catch (DbEntityValidationException e) //{ // CommonRepository.HandleDbEntityValidationException(e); //} return(list); }
public Core.Entities.BalanceDate Read(int id) { Core.Entities.BalanceDate entity = null; using (FinanceEntities context = factory.CreateContext()) { var ef = ReadQuery(context, id).FirstOrDefault(); //var ef = (from b in context.BalanceDates // .Include(a => a.BalanceDateBankAccounts) // .Include("BalanceDateBankAccounts.BankAccount") // .Include("BalanceDateBankAccounts.BankAccount.Bank") // where b.BalanceDateId==id // select b).FirstOrDefault(); entity = mapper.Map <Core.Entities.BalanceDate>(ef); } return(entity); }
public Core.Entities.Transfer Read(int id) { Core.Entities.Transfer entity = null; using (FinanceEntities context = factory.CreateContext()) { var ef = (from b in context.Transfers .Include(a => a.FromBankAccount) .Include(a => a.FromBankAccount.Bank) .Include(a => a.ToBankAccount) .Include(a => a.ToBankAccount.Bank) .Include(a => a.TransferCategory) where b.TransferId == id select b).FirstOrDefault(); entity = mapper.Map <Core.Entities.Transfer>(ef); } return(entity); }
public List <Core.Entities.Transfer> ReadList() { List <Core.Entities.Transfer> list = null; using (FinanceEntities context = factory.CreateContext()) { var ef = (from b in context.Transfers .Include(a => a.FromBankAccount) .Include(a => a.FromBankAccount.Bank) .Include(a => a.ToBankAccount) .Include(a => a.ToBankAccount.Bank) .Include(a => a.TransferCategory) select b).ToList(); list = mapper.Map <List <Core.Entities.Transfer> >(ef); } return(list); }
public async Task PostList(ITargetBlock <Core.Entities.BalanceDate> target) { Diag.ThreadPrint("PostList - start"); var transform = new TransformBlock <BalanceDate, Core.Entities.BalanceDate>(ef => mapper.Map <Core.Entities.BalanceDate>(ef), new ExecutionDataflowBlockOptions() { MaxDegreeOfParallelism = 4 }); transform.LinkTo(target, new DataflowLinkOptions() { PropagateCompletion = true }); await Task.Run(() => { Diag.ThreadPrint("PostList - task start"); using (FinanceEntities context = factory.CreateContext()) { (from b in context.BalanceDates .Include(a => a.BalanceDateBankAccounts) .Include("BalanceDateBankAccounts.BankAccount") .Include("BalanceDateBankAccounts.BankAccount.Bank") select b).AsParallel().ForAll(ef => transform.Post(ef)); //await transform.Completion; //transform.Completion.ContinueWith(t => //{ // if (t.IsFaulted) target.Fault(t.Exception); // else // { // Diag.ThreadPrint("PostList - task set target complete"); // target.Complete(); // } //}); transform.Complete(); } Diag.ThreadPrint("PostList - task end"); }).ConfigureAwait(false); Diag.ThreadPrint("PostList - end"); }
public int Add(Core.Entities.Cashflow entity) { int id = 0; //try //{ var ef = mapper.Map <Cashflow>(entity); using (FinanceEntities context = factory.CreateContext()) { context.Entry(ef).State = EntityState.Added; context.SaveChanges(); } //read back columns which may have changed entity.CashflowId = ef.CashflowId; entity.RecordCreatedDateTime = ef.RecordCreatedDateTime; entity.RecordUpdatedDateTime = ef.RecordUpdatedDateTime; int i = 0; foreach (var cba in ef.CashflowBankAccounts) { if (entity.CashflowBankAccounts.Count <= i) { break; } var e = entity.CashflowBankAccounts[i]; e.CashflowBankAccountId = cba.CashflowBankAccountId; e.RecordCreatedDateTime = cba.RecordCreatedDateTime; i++; } id = ef.CashflowId; //} //catch (DbEntityValidationException e) //{ // CommonRepository.HandleDbEntityValidationException(e); //} return(id); }
public bool Delete(Core.Entities.Cashflow entity) { //try //{ var ef = mapper.Map <Cashflow>(entity); ef.CashflowBankAccounts.Clear(); using (FinanceEntities context = factory.CreateContext()) { context.Entry(ef).State = EntityState.Deleted; // deletes are cascaded to CashflowBankAccount context.SaveChanges(); } //} //catch (DbEntityValidationException e) //{ // CommonRepository.HandleDbEntityValidationException(e); //} return(true); }
public List <Core.Entities.Cashflow> ReadList() { List <Core.Entities.Cashflow> list = null; //try //{ using (FinanceEntities context = factory.CreateContext()) { var ef = (from b in context.Cashflows .Include(a => a.CashflowBankAccounts) .Include("CashflowBankAccounts.BankAccount") .Include("CashflowBankAccounts.BankAccount.Bank") select b).ToList(); list = mapper.Map <List <Core.Entities.Cashflow> >(ef); } //} //catch (DbEntityValidationException e) //{ // CommonRepository.HandleDbEntityValidationException(e); //} return(list); }
public Core.Entities.Cashflow Read(int id) { Core.Entities.Cashflow entity = null; //try //{ using (FinanceEntities context = factory.CreateContext()) { var ef = (from b in context.Cashflows .Include(a => a.CashflowBankAccounts) .Include("CashflowBankAccounts.BankAccount") .Include("CashflowBankAccounts.BankAccount.Bank") where b.CashflowId == id select b).FirstOrDefault(); entity = mapper.Map <Core.Entities.Cashflow>(ef); } //} //catch (DbEntityValidationException e) //{ // CommonRepository.HandleDbEntityValidationException(e); //} return(entity); }
public int Add(Core.Entities.BalanceDate entity) { int id = 0; var ef = mapper.Map <BalanceDate>(entity); using (FinanceEntities context = factory.CreateContext()) { context.Entry(ef).State = EntityState.Added; context.SaveChanges(); } //read back columns which may have changed entity.BalanceDateId = ef.BalanceDateId; entity.RecordCreatedDateTime = ef.RecordCreatedDateTime; //entity.RecordUpdatedDateTime = ef.RecordUpdatedDateTime; int i = 0; foreach (var cba in ef.BalanceDateBankAccounts) { if (entity.BalanceDateBankAccounts.Count <= i) { break; } var e = entity.BalanceDateBankAccounts[i]; e.BalanceDateBankAccountId = cba.BalanceDateBankAccountId; e.RecordCreatedDateTime = cba.RecordCreatedDateTime; i++; } id = ef.BalanceDateId; return(id); }
string ShowEntityStates(FinanceEntities context) { var sb = new StringBuilder(); foreach (var entity in context.ChangeTracker.Entries()) { sb.AppendFormat("{0}-{1}", entity.Entity.GetType().Name, entity.State.ToString()); sb.AppendLine(); } return sb.ToString(); }
public bool Update(Core.Entities.BalanceDate entity) { var ef = mapper.Map <BalanceDate>(entity); using (FinanceEntities context = factory.CreateContext()) { // read in children var cbas = from b in context.BalanceDateBankAccounts where b.BalanceDateId == ef.BalanceDateId select b; foreach (var cba in cbas) { if (ef.BalanceDateBankAccounts.Count(a => a.BalanceDateBankAccountId == cba.BalanceDateBankAccountId) == 0) { context.Entry(cba).State = EntityState.Deleted; } else { context.Entry(cba).State = EntityState.Detached; } } foreach (var cba in ef.BalanceDateBankAccounts) { if (cba.BalanceDateBankAccountId > 0) { context.Entry(cba).State = EntityState.Modified; } else { context.Entry(cba).State = EntityState.Added; } } context.Entry(ef).State = EntityState.Modified; var s = ShowEntityStates(context); context.SaveChanges(); } //read back data which may have changed //entity.RecordUpdatedDateTime = ef.RecordUpdatedDateTime; int i = 0; foreach (var cba in ef.BalanceDateBankAccounts) { if (entity.BalanceDateBankAccounts.Count <= i) { break; } var e = entity.BalanceDateBankAccounts[i]; e.BalanceDateBankAccountId = cba.BalanceDateBankAccountId; e.RecordCreatedDateTime = cba.RecordCreatedDateTime; i++; } return(true); }
private IQueryable<BalanceDate> ReadQuery(FinanceEntities context, int? id=null) { return (from b in context.BalanceDates .Include(a => a.BalanceDateBankAccounts) .Include("BalanceDateBankAccounts.BankAccount") .Include("BalanceDateBankAccounts.BankAccount.Bank") where !id.HasValue || b.BalanceDateId == id select b); }
public FinanceEntities CreateContext() { var context = new FinanceEntities(this.EFConnectionString); context.Configuration.LazyLoadingEnabled = false; return context; }
public bool Update(Core.Entities.Cashflow entity) { //throw new Exception("testing"); //try //{ var ef = mapper.Map <Cashflow>(entity); using (FinanceEntities context = factory.CreateContext()) { // read in children var cbas = from b in context.CashflowBankAccounts where b.CashflowId == ef.CashflowId select b; foreach (var cba in cbas) { if (ef.CashflowBankAccounts.Count(a => a.CashflowBankAccountId == cba.CashflowBankAccountId) == 0) { context.Entry(cba).State = EntityState.Deleted; } else { context.Entry(cba).State = EntityState.Detached; } } foreach (var cba in ef.CashflowBankAccounts) { if (cba.CashflowBankAccountId > 0) { context.Entry(cba).State = EntityState.Modified; } else { context.Entry(cba).State = EntityState.Added; } } context.Entry(ef).State = EntityState.Modified; var s = ShowEntityStates(context); context.SaveChanges(); } //read back data which may have changed entity.RecordUpdatedDateTime = ef.RecordUpdatedDateTime; int i = 0; foreach (var cba in ef.CashflowBankAccounts) { if (entity.CashflowBankAccounts.Count <= i) { break; } var e = entity.CashflowBankAccounts[i]; if (e.CashflowBankAccountId == 0) { e.CashflowBankAccountId = cba.CashflowBankAccountId; e.RecordCreatedDateTime = cba.RecordCreatedDateTime; } i++; } //} //catch (DbEntityValidationException e) //{ // CommonRepository.HandleDbEntityValidationException(e); //} return(true); }