Fetching Strategy example in repository pattern with pure POCO Entity framework
Posted
by
Shawn Mclean
on Stack Overflow
See other posts from Stack Overflow
or by Shawn Mclean
Published on 2011-01-16T17:31:06Z
Indexed on
2011/01/17
11:53 UTC
Read the original article
Hit count: 285
I'm trying to roll out a strategy pattern with entity framework and the repository pattern using a simple example such as User
and Post
in which a user has many posts.
From this answer here, I have the following domain:
public interface IUser {
public Guid UserId { get; set; }
public string UserName { get; set; }
public IEnumerable<Post> Posts { get; set; }
}
Add interfaces to support the roles in which you will use the user.
public interface IAddPostsToUser : IUser {
public void AddPost(Post post);
}
Now my repository looks like this:
public interface IUserRepository {
User Get<TRole>(Guid userId) where TRole : IUser;
}
Strategy (Where I'm stuck). What do I do with this code? Can I have an example of how to implement this, where do I put this?
public interface IFetchingStrategy<TRole> {
TRole Fetch(Guid id, IRepository<TRole> role)
}
My basic problem was what was asked in this question. I'd like to be able to get Users without posts and users with posts using the strategy pattern.
© Stack Overflow or respective owner