protected override DataSyncContext CreateDataContext() { var context = new DataContext(); //These columns cannot be added in the strongly-typed row //because the People table must be usable without pledges //or payments. (eg, ListMaker or Rafflizer) if (!Person.Schema.Columns.Contains("TotalPaid")) //This can be called multiple times in the designer AppDomain { Person.Schema.Columns.AddCalculatedColumn <Person, decimal>("TotalPaid", person => person.Payments.Sum(p => p.Amount)); Person.Schema.Columns.AddCalculatedColumn <Person, decimal>("TotalPledged", person => person.Pledges.Sum(p => p.Amount)); Person.Schema.Columns.AddCalculatedColumn <decimal>("BalanceDue", person => person.Field <decimal>("TotalPledged") - person.Field <decimal>("TotalPaid")); Payment.Schema.Columns.RemoveColumn(Payment.DepositColumn); ValueColumn uiidColumn = Person.Schema.Columns.AddValueColumn(nameof(Extensions.UIId), typeof(int?), null); Person.SchemaMapping.Columns.RemoveMapping(uiidColumn); } context.Tables.AddTable(Pledge.CreateTable()); context.Tables.AddTable(Payment.CreateTable()); context.Tables.AddTable(EmailAddress.CreateTable()); context.Tables.AddTable(Person.CreateTable()); var dsc = new DataSyncContext(context, new SqlServerSqlProvider(DB.Default)); dsc.Tables.AddPrimaryMappings(); return(dsc); }
protected override DataSyncContext CreateDataContext() { var context = new DataContext(); //These columns cannot be added in the strongly-typed row //because the People table must be usable without pledges //or payments. (eg, ListMaker or Rafflizer) if (!Person.Schema.Columns.Contains("TotalPaid")) //This can be called multiple times in the designer AppDomain { Person.Schema.Columns.AddCalculatedColumn <Person, decimal>("TotalPaid", person => person.Payments.Sum(p => p.Amount)); Person.Schema.Columns.AddCalculatedColumn <Person, decimal>("TotalPledged", person => person.Pledges.Sum(p => p.Amount)); Person.Schema.Columns.AddCalculatedColumn <decimal>("BalanceDue", person => person.Field <decimal>("TotalPledged") - person.Field <decimal>("TotalPaid")); Pledge.Schema.Columns.AddCalculatedColumn <Pledge, decimal>("UnlinkedAmount", p => p.Amount <= 0 ? 0 : p.Amount - p.LinkedPayments.Sum(o => o.Amount)); EmailAddress.PersonColumn.AddIndex(); Pledge.PersonColumn.AddIndex(); Payment.PersonColumn.AddIndex(); PledgeLink.PaymentColumn.AddIndex(); PledgeLink.PledgeColumn.AddIndex(); } context.Tables.AddTable(PledgeLink.CreateTable()); context.Tables.AddTable(Payment.CreateTable()); context.Tables.AddTable(Pledge.CreateTable()); context.Tables.AddTable(EmailAddress.CreateTable()); context.Tables.AddTable(LoggedStatement.CreateTable()); context.Tables.AddTable(Person.CreateTable()); context.Tables.AddTable(Deposit.CreateTable()); context.Tables.AddTable(RelativeLink.CreateTable()); if (IsDesignTime) { AddDesignTimeTables(context); } var syncContext = new DataSyncContext(context, new SqlServerSqlProvider(DB.Default)); syncContext.Tables.AddPrimaryMappings(); return(syncContext); }