Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What a great question. First of all, it's so refreshing to see someone asking about the <em>proper</em> way to do something, rather that just seeking a quick fix. Second, the amount of documentation provided is exactly the way SO questions should be written. I wish I could give this more than +1.</p> <p>That said, since you're essentially asking an architecture question, there aren't any concrete answers, just opinions.</p> <p>Here's my opinion:</p> <p>You state the result of the sproc is mapped to a domain model:</p> <pre><code>var resultFaxDS = vOEIDAO.GetFaxLogSearchResult(startDate,endDate,userName,faxType); </code></pre> <p>However, you've added a return field, <code>CustomerName</code> to your sproc which is not part of the domain model. I think that's the heart of your issue.</p> <p>There's a choice to be made here: does this sproc return a domain model or doesn't it?</p> <p>Right now, my opinion is that it does not represent a domain model anymore, due to the new field, so you should not be trying to map it to a domain model before mapping it to your view model. You need to create a new data type to map this result to, which represents what you are actually getting from the sproc, and map <em>that</em> to your view model.</p> <p>The alternate option is that this sproc does in fact represent a domain model. If that is the case, you should not be adding a new field to it that is not part of the model. Rather, you'll need to get the <code>FaxModel</code> domain objects and <code>CustomerModel</code> domain objects separately, and assemble your view models from both objects.</p> <p>This is an example of the <strong>Single Responsibility Principle</strong>, meaning that an object, function, assembly, heck, even a program, should have <em>one</em> purpose. By giving your sproc a return value that both is and isn't a domain model, you're giving it more than one purpose. It would be best to either decide that it represents a <code>FaxModel</code>, and accept that the customer name needs to come from another source, or decide that it returns something else, say <code>CustomerFaxModel</code> which contains both customer and fax information, and use it as such.</p> <p>To answer your technical question, AutoMapper does allow you to pass an existing target object to the map function in addition to a source object. You can map the target from object A to get some fields, and then pass the already mapped target to <code>Map()</code> a second time with a source of object B to map other fields.</p> <p>Always, always, keep asking questions like this and you'll do well.</p>
    singulars
    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. This table or related slice is empty.
    1. This table or related slice is empty.
    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