|
|
@@ -153,7 +153,8 @@ namespace OHV.SqliteDAL.DAL
|
|
|
|
|
|
public IEnumerable<T> GetAll()
|
|
|
{
|
|
|
- return table.ToList();
|
|
|
+ lock ( this.lockObj )
|
|
|
+ return table.ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -161,65 +162,82 @@ namespace OHV.SqliteDAL.DAL
|
|
|
{
|
|
|
IQueryable<T> query = this.table;
|
|
|
|
|
|
- if ( filter != null )
|
|
|
- query = query.Where( filter );
|
|
|
-
|
|
|
- if ( includeProperties != null )
|
|
|
+ lock ( this.lockObj )
|
|
|
{
|
|
|
- foreach ( var includeProperty in includeProperties.Split( new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries ) )
|
|
|
- query = query.Include( includeProperty );
|
|
|
- }
|
|
|
|
|
|
- if ( orderBy != null )
|
|
|
- return orderBy( query ).ToList();
|
|
|
- else
|
|
|
- return query.ToList();
|
|
|
+ if ( filter != null )
|
|
|
+ query = query.Where( filter );
|
|
|
+
|
|
|
+ if ( includeProperties != null )
|
|
|
+ {
|
|
|
+ foreach ( var includeProperty in includeProperties.Split( new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries ) )
|
|
|
+ query = query.Include( includeProperty );
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( orderBy != null )
|
|
|
+ return orderBy( query ).ToList();
|
|
|
+ else
|
|
|
+ return query.ToList();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public T GetById( object id )
|
|
|
{
|
|
|
- return table.Find( id );
|
|
|
+ lock ( this.lockObj )
|
|
|
+ return table.Find( id );
|
|
|
}
|
|
|
public void Insert( T obj )
|
|
|
{
|
|
|
- table.Add( obj );
|
|
|
- this.Save();
|
|
|
+ lock ( this.lockObj )
|
|
|
+ {
|
|
|
+ table.Add( obj );
|
|
|
+ this.Save();
|
|
|
+ }
|
|
|
}
|
|
|
public void Update( T obj )
|
|
|
{
|
|
|
- table.Attach( obj );
|
|
|
- _context.Entry( obj ).State = EntityState.Modified;
|
|
|
- this.Save();
|
|
|
+ lock ( this.lockObj )
|
|
|
+ {
|
|
|
+ table.Attach( obj );
|
|
|
+ _context.Entry( obj ).State = EntityState.Modified;
|
|
|
+ this.Save();
|
|
|
+ }
|
|
|
}
|
|
|
public void Delete( object id )
|
|
|
{
|
|
|
- T existing = table.Find( id );
|
|
|
- table.Remove( existing );
|
|
|
- this.Save();
|
|
|
+ lock ( this.lockObj )
|
|
|
+ {
|
|
|
+ T existing = table.Find( id );
|
|
|
+ table.Remove( existing );
|
|
|
+ this.Save();
|
|
|
+ }
|
|
|
}
|
|
|
public void Delete( Expression<Func<T, bool>> filter )
|
|
|
{
|
|
|
- var delList = this.table.Where( filter ).ToList();
|
|
|
- if ( delList.Count > 0 )
|
|
|
+ lock ( this.lockObj )
|
|
|
{
|
|
|
- this.table.RemoveRange( delList );
|
|
|
- Save();
|
|
|
+ var delList = this.table.Where( filter ).ToList();
|
|
|
+ if ( delList.Count > 0 )
|
|
|
+ {
|
|
|
+ this.table.RemoveRange( delList );
|
|
|
+ Save();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void Clean()
|
|
|
- {
|
|
|
- table.RemoveRange( table );
|
|
|
- this.Save();
|
|
|
- }
|
|
|
- public void Save()
|
|
|
{
|
|
|
lock ( this.lockObj )
|
|
|
{
|
|
|
- _context.SaveChanges();
|
|
|
- this.OnChangeTable?.BeginInvoke( null, null );
|
|
|
+ table.RemoveRange( table );
|
|
|
+ this.Save();
|
|
|
}
|
|
|
}
|
|
|
+ public void Save()
|
|
|
+ {
|
|
|
+ _context.SaveChanges();
|
|
|
+ this.OnChangeTable?.BeginInvoke( null, null );
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public interface IGenericRepository<T> where T : class
|