Skip to content

Simple Retrieve

Max Stepanskiy edited this page Mar 31, 2021 · 13 revisions

Overview

  • Maps ADO.NET results to specified DTO's
  • Executes direct SQL statements when a sql parameter is passed
  • Otherwise executes a stored procedure based on the configurable naming convention and optional operation parameter value

Simple retrieve with dynamic parameters

Use various types of dynamic parameters

// Executes RetrieveCustomer stored procedure given provided configuration
ConfigurationFactory.Configure().SetDefaultOperationNamingConvention(OperationNamingConvention.OperationTypeName);
// Parameters can be defined as a list of lambda expressions
var retrieve_customer_dyn1 = ObjectFactory.Retrieve<Customer>(parameters: new ParamList { CustomerID => "ALFKI" });
// Parameters can be defined as an anonymous object
var retrieve_customer_dyn2 = ObjectFactory.Retrieve<Customer>(parameters: new { CustomerID = "ALFKI" });
// Parameters can be defined as dictionary
var retrieve_customer_dyn3 = ObjectFactory.Retrieve<Customer>(parameters: new Dictionary<string, object> { { "CustomerID", "ALFKI" } });

Simple retrieve with actual parameters

// Executes RetrieveCustomer stored procedure given provided configuration
ConfigurationFactory.Configure().SetDefaultOperationNamingConvention(OperationNamingConvention.OperationTypeName);
var retrieve_customer = ObjectFactory.Retrieve<Customer>(parameters: new[] { new Param { Name = "CustomerID", 
                                                                                         Value = "ALFKI" } });

Simple retrieve with dynamic parameters and custom operation name

// Executes RetrieveCustomersByCountrystored procedure by default
var retrieve_customers_by_country = ObjectFactory.Retrieve<Customer>(operation: "RetrieveCustomersByCountry", 
                                                             parameters: new ParamList { Country => "USA" });

Simple retrieve with parameterized sql query instead of an operation name

var retrieve_customer_sql = ObjectFactory.Retrieve<Customer>(
                                               sql: "select * from Customers where CustomerID = @CustomerID", 
                                               parameters: new ParamList { CustomerID => "ALFKI" });

Click here for advanced retrieve features.