[HttpGet]
public ViewResult TablesContent()
{
var traceTree = _traceTreesRepository.Record();
traceTree.RecordCodeMethodExecution(MethodBase.GetCurrentMethod());
var customers = _tableContentRepository.GetItems<CustomerTable, Customer>(traceTree);
// Tracing disabled for other tables to keep it concise.
var addresses = _tableContentRepository.GetItems<AddressTable, Address>(null);
var purchases = _tableContentRepository.GetItems<PurchaseTable, Purchase>(null);
var products = _tableContentRepository.GetItems<ProductTable, Demos.ReportGenerator.Domain.Product>(null);
var productPriceHistories = _tableContentRepository.GetItems<ProductPriceHistoryTable, ProductPriceHistory>(null);
var contentModel = new TablesContentModel(
_traceTreesRepository.RootTraceTree,
customers,
addresses,
purchases,
products,
productPriceHistories);
return View(contentModel);
}
public IReadOnlyList<TItem> GetItems<TItem>(
/*WYSE*/ISelect select,
Converter<DbDataReader, TItem> converter,
TraceTree parentTraceTree)
{
var traceTree = parentTraceTree?.AddChild();
traceTree?.RecordCodeMethodExecution(MethodBase.GetCurrentMethod());
using SqlConnection connection = _connectionFactory.Create();
connection.Open();
// Aliases and parameter names can be given custom values.
// If omitted, unique identifer values are supplied
// In the case of this Demo, these generated values are overwritten,
// based on the current render settings, with more legible values.
// WYSE supports several kinds of Resetting/renaming.
ResetIdentifiers(select);
using SqlCommand command = connection.CreateCommand()
// A WYSE Render context determines certain (overridable) render settings.
// Here the context is SqlServer. More SQL flavors are supported.
// A WYSE render builder is used for stringifying
// the strongly typed SQL statements.
/*WYSE*/.For(select, _renderContextFactory.Create(), _createRenderBuilder);
try
{
using DbDataReader reader = command.ExecuteReader();
var items = reader.GetItems(select, converter).ToList();
traceTree?.RecordDbCommandExecutionSuccess(command.CommandText, items);
return items;
}
catch (Exception exception)
{
traceTree?.RecordDbCommandExecutionFailure(command.CommandText, exception);
return default;
}
}