I am writing a project in MVC and am using EF 4.0. I am using the repository pattern but am unsure about where to place some properties.
public interface IUserRepository<User>
{
User GetUserById(int userId);
void UpdateUser(User user);
void AddUser(User user);
List<User> GetUsersByName(string userName);
void Create(User user);
int NumberOfFollowers { get; set; }
}
My two problems are 1). should the property NumberOfFollowers
be a property or a method?
and 2). should it be placed inside the User entity class instead of the interface?
cheers.
If NumberOfFollowers
is a property of a User, it should definitely be on the User
class, not the repository. The repository is responsible for getting/putting data only.
Here is my favorite repository implementation for EF:
http://www.codeproject.com/KB/database/ImplRepositoryPatternEF.aspx
This one is terrific, very complete and comes with a lot of features.