DDD

DDD and ASP.NET MVC

I find myself adding child objects within their parents control. For example; if I was going to add a child. I would call the parents controllers addChild action.

/parent/addChild/2

In this case 2 would be the id of the parent that I wanted to add a child to.

Doing it this way I don’t have to keep an internal track of which parent the user wants to add a child to.

For example /child/create does not tell me what parent I am going to associate the child with. In this scenario I would have to put the parent ID in session or something first.

Not sure if what I am doing is “right”….I think so.

Tags: ,

Sunday, May 17th, 2009 DDD, mvc 4 Comments

Entity Framework, Aggregate Root, One-to-Many & DDD

I’m really digging the DDD Aggregate root design pattern and thought it would be good to create an example of using EF to pull a root from the persistence layer (database).

My database:

image

In my little database prjects have releases and stories. releases have sprints and stories and stories have tasks. My root is a project.

 

My model (EF)

image

A method for pulling the root:

Its important to note that child objects must be included in the query. ex: Include("Stories.Tasks") will get the tasks.

All the projects

Dim _entities As Entities.EntityFrameworkEntities = New Entities.EntityFrameworkEntitiesReturn
_entities.Projects().Include("Releases").Include("Stories").Include("Stories.Tasks")

A specific project.

Function GetById(ByVal Id As Integer) As Entities.Projects       
Return _entities.Projects().Include("Releases").Include("Stories").Include("Stories.Tasks").Where(Function(p) p.ProjectId = Id).FirstOrDefault
End Function

Tags: , ,

Thursday, April 30th, 2009 DDD, Entity Framework No Comments

Search