Where does this go? Applying SoC to dynamic data – Part 3

Since a major goal of Dynamic Data is to separate the business logic from the user interface, let’s look at a few areas where these concepts still blend and their alternatives.

Today we look at the…

DataSource controls

In the previous parts, we explored how Dynamic Data introduced UI specific information into the business layer. Now we’ll look at how business logic finds its way into the UI layer through the DataSource controls.

When creating a web form, Dynamic Data requires a DataSource control to handle the CRUD (“create, read, update, and delete”) actions. There are two classic DataSource controls for Dynamic Data: LinqDataSource (for LINQ to SQL) and EntityDataSource (for ADO.NET Entity Framework). When you set them up, you don’t handle the Update, Insert, and Delete actions. These controls have those actions built in. But not queries.

You have to write queries, using a variety of mechanisms, but in the end, the user interface developer has to do some work that should be in the business layer.

Take a look at ScottGu’s example for the ListView control. About 1/3 of the way down shows this screen shot:

step19

There’s a query in Page_Load. It belongs in the business logic.

How do you fix this?

You must strongly enforce separation of concerns by creating classes in the middle tier that host your queries. The techiques involve switching to different DataSource controls.

  • DomainDataSource – Found in RIA Services, which is in preview releases at this point. When using “Domains”, you create a single class that hosts all of your CRUD methods including queries. The DomainDataSource needs to know the names of the methods you intend to use.
    Learn more with Guy Burstein’s posting.
  • EntityDAODataSource – From my Versatile DataSources, which is on CodePlex. You define a Data Access Object class for each Entity class. It hosts all CRUD methods including queries. The EntityDAODataSource needs to know the name of the Entity type and the query method.
    Learn more with my earlier posting.

1 Comment

  • Thanks for that explanation. Will check out the EntityDAODataSource.
    [Peter's comments]. Also see my blog entry on the subject: DataSources, Dynamic Data, and SoC.


Comments have been disabled for this content.