using System; using System.Collections.Generic; using ConsoleApp1.Model; using ConsoleApp1.ORM; namespace ConsoleApp1.Repository { public interface PersonRepository { /// /// Get person entity by id /// /// id /// person Person Get(Guid id); /// /// Save person entity /// /// person void Save(Person person); /// /// Update person entity /// /// person void Update(Person person); /// /// Delete person entity /// /// person void Delete(Person person); /// /// Row count person in db /// /// number of rows long RowCount(); void Save(IEnumerable persons); } public class PersonRepositoryNHibernate : PersonRepository { public void Save(IEnumerable persons) { BulkQuery.BulkInsert(persons); } public void Save(Person person) { using var session = NHibernateHelper.OpenSession(); using var transaction = session.BeginTransaction(); session.Save(person); transaction.Commit(); } public Person Get(Guid id) { using var session = NHibernateHelper.OpenSession(); return session.Get(id); } public void Update(Person person) { using var session = NHibernateHelper.OpenSession(); using var transaction = session.BeginTransaction(); session.Update(person); transaction.Commit(); } public void Delete(Person person) { using var session = NHibernateHelper.OpenSession(); using var transaction = session.BeginTransaction(); session.Delete(person); transaction.Commit(); } public long RowCount() { using var session = NHibernateHelper.OpenSession(); return session.QueryOver().RowCountInt64(); } } }