У меня есть интерфейс IRepository
для абстрагирования моего репозитория:
Поддельный репозиторий
public class Repository : IRepository
{
IQueryable<User> _users;
public IQueryable<User> Users
{
get
{
return _users ?? (_users = Enumerable.Empty<User>().AsQueryable());
}
}
IQueryable<Couple> _couples;
public IQueryable<Couple> Couples
{
get
{
return _couples ?? (_couples = Enumerable.Empty<Couple>().AsQueryable());
}
}
IQueryable<Role> _roles;
public IQueryable<Role> Roles
{
get
{
return _roles ?? (_roles = Enumerable.Empty<Role>().AsQueryable());
}
}
public T Add<T>(T entity) where T : class
{
throw new System.NotImplementedException(); //Problem here!!
}
}
Мне нужно знать, как добавить объект в нужную коллекцию в мою подделку репозитория?
В моем хранилище базы данных у меня нет этой проблемы:
Репозиторий базы данных
public class Repository : DbContext, IRepository
{
public DbSet<Role> Roles { get; set; }
public DbSet<User> Users { get; set; }
public DbSet<Couple> Couples { get; set; }
public T Add<T>(T entity)
where T : class
{
return Set<T>().Add(entity);
}
... //More...
}
Я знаю, что коллекции не одного типа, скрыл эту реализациюсократить код.
Все, что я хочу знать, это как сохранить то же поведение из моего хранилища базы данных в моем поддельном хранилище?