Search code examples
asp.net-mvcdesign-patternsdto

Ways to pass a DTO object representing user's search criteria to the DAL


I have an MVC app divided into the usual layers: MVC presentation layer, Business Logic, and Data Access Layer.

In the MVC app I have a search form. It's a complex one - lots of checkboxes, radios, dropdowns and text fields. When the user submits the form I create an "EditModel" (ActionModel?) object in the Controller that contains a set of properties encapsulating the form.

The DAL needs to use the properties in this object to construct a query that returns the right results based on the user's selection.

What is the best way of passing this through to the DAL (which obviously has no reference to the MVC project). Is it to create a DTO which is exactly the same as the EditModel (ActionModel?) , just for the purposes of passing it from MVC -> BLL -> DAL? Are there any better ways?


Solution

  • If the object would truly be "exactly the same," why wouldn't you just use it in the BLL and DAL? It would make sense to have an assembly referenced by both the model and the BLL (and DAL).