Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Maybe an example will help here...</p> <p>Let's say you have a nicely-normalized database schema like this:</p> <pre> Orders (OrderID, CustomerID, OrderDate) Customers (CustomerID, Name) OrderDetails (OrderDetID, OrderID, ProductID, Qty) Products (ProductID, ProductName, UnitPrice) </pre> <p>And let's say you're using a nice O/R mapper that hands you back a well-organized domain model:</p> <pre> OrderDetail +--ID +--Order |--+--Date |--+--Customer |-----+--ID |-----+--Name +--Product |--+--ID |--+--Name |--+--UnitPrice +--Qty </pre> <p>Now you're given a requirement to display everything that's been ordered in the last month. You want to bind this to a flat grid, so you dutifully write a flat class to bind:</p> <pre><code>public class OrderDetailDto { public int ID { get; set; } public DateTime OrderDate { get; set; } public int OrderCustomerID { get; set; } public string OrderCustomerName { get; set; } public int ProductID { get; set; } public string ProductName { get; set; } public Decimal ProductUnitPrice { get; set; } public int Qty { get; set; } public Decimal TotalPrice { get { return ProductUnitPrice * Qty; } } } </code></pre> <p>That was pretty painless so far, but what now? How do we turn a bunch of <code>OrderDetail</code>s into a bunch of <code>OrderDetailDto</code>s for data binding?</p> <p>You might put a constructor on <code>OrderDto</code> that takes an <code>OrderDetail</code>, and write a big mess of mapping code. Or you might have a static conversion class somewhere. Or, you could use AutoMapper, and write this instead:</p> <pre><code>Mapper.CreateMap&lt;OrderDetail, OrderDetailDto&gt;(); OrderDetailDto[] items = Mapper.Map&lt;OrderDetail[], OrderDetailDto[]&gt;(orderDetails); GridView1.DataSource = items; </code></pre> <p>There. We've just taken what would otherwise have been a disgusting mess of pointless mapping code and reduced it into three lines (really just two for the actual mapping).</p> <p>Does that help explain the purpose?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload