Я видел несколько примеров приложений с использованием ASP.NET MVC Unit of Work в классе контекста для совершения фиксации транзакций.MVC Unit Of Work
Это хорошая практика ??
public interface IUnitOfWork
{
void Commit()
}
public class DatabaseContext : DbContext, IUnitOfWork
{
public DbSet<Entity> Entity { get; set; }
public void Commit()
{
base.SaveChanges();
}
}
public class EntityRepository : IRepository<Entity>
{
private DatabaseContext _context;
public EntityRepository(DatabaseContext Context)
{
_context = Context;
}
void Insert()
{
_context.Entities.Add(Entity);
}
void Save()
{
_context.Commit();
}
}
Или его лучше
public interface IUnitOfWork
{
void Commit()
}
public class DatabaseContext : DbContext
{
public DbSet<Entity> Entity { get; set; }
}
public class EntityRepository : IRepository<Entity>, IUnitOfWork
{
private DatabaseContext _context;
public EntityRepository(DatabaseContext Context)
{
_context = Context;
}
void Insert()
{
_context.Entities.Add(Entity);
}
void Commit()
{
_context.SaveChanges();
}
}
Я не знаю об этом approuch, что у сказать ????
Если все, что существует в '' Commit' является base.SaveChanges() 'Я не уверен, где значение здесь. Кроме того, вы явно не реализовали это, потому что код, который у вас есть, даже не будет компилироваться. –
Эй, парень, я отредактировал вопрос :) – leojnxs