没有编辑的存储库模式

时间:2016-08-07 00:04:18

标签: c# repository

我正在阅读C#中的存储库模式。我用示例存储库读取的每篇文章如下所示,并且不包含Edit实体的定义。

    TEntity Get(TKey id);
    void Save(TEntity entity);
    void Delete(TEntity entity);

在基本存储库界面中使用Edit方法是不是很糟糕?

   public interface IRepositor<T>
    {
        void Edit(Predicate<T> predicate, Action<T> action);
    } 




  public class Car : IRepository<Car>
    {
        public void Edit(Predicate<Car> predicate, Action<Car> action)
        {
            var car = Context.Cars.SingleOrDefault(x => predicate(x));

            if(car == null) throw new Exception("Not found");

            action.Invoke(car);



        }
    }

public class CarController
{
    public void Edit(CarViewModel vm)
    {
        carService.Edit(x => x.Id == vm.Id, y => y.Type == "BMW" );
    }
}

0 个答案:

没有答案
相关问题