Frage

Let's say we have a web page that is supposed to have 1 post collection (title, date) and a list of posts (title, body).

I can visualise a view model like:

public class PostCollectionViewModel
{
  public PostCollectionHeader PostCollectionHeader {get;set;}
  public List<Post> Posts {get;set;}
}

Should I call two business layer methods to fill these two view model properties or should I have a single business layer method that should return a post collection with posts?

War es hilfreich?

Lösung

If you separate the queries from the commands (command-query separation), you could have a specific query that returns what you need with one request - nothing more and nothing less. This query can bypass the business layer (therefore avoiding the unneeded overhead), and talk to the database directly. See example here.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top