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

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 
© 2012 eric.polerecky.com Suffusion theme by Sayontan Sinha