|
|
@@ -163,37 +163,46 @@ namespace OHV.SqliteDAL.DAL
|
|
|
|
|
|
public IEnumerable<T> GetAll()
|
|
|
{
|
|
|
- return table.ToList();
|
|
|
+ lock ( lockObj )
|
|
|
+ return table.ToList();
|
|
|
}
|
|
|
|
|
|
public virtual IEnumerable<T> Get( Expression<Func<T, bool>> filter = null, Func<IQueryable<T>, IOrderedQueryable<T>> orderBy = null, string includeProperties = "" )
|
|
|
{
|
|
|
- IQueryable<T> query = this.table;
|
|
|
+ lock ( lockObj )
|
|
|
+ {
|
|
|
|
|
|
- if ( filter != null )
|
|
|
- query = query.Where( filter );
|
|
|
+ IQueryable<T> query = this.table;
|
|
|
|
|
|
- if ( includeProperties != null )
|
|
|
- {
|
|
|
- foreach ( var includeProperty in includeProperties.Split( new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries ) )
|
|
|
- query = query.Include( includeProperty );
|
|
|
- }
|
|
|
+ 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();
|
|
|
+ if ( orderBy != null )
|
|
|
+ return orderBy( query ).ToList();
|
|
|
+ else
|
|
|
+ return query.ToList();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public T GetById( object id )
|
|
|
{
|
|
|
- return table.Find( id );
|
|
|
+ lock ( lockObj )
|
|
|
+ return table.Find( id );
|
|
|
}
|
|
|
|
|
|
public void Insert( T obj )
|
|
|
{
|
|
|
- table.Add( obj );
|
|
|
- this.Save();
|
|
|
+ lock ( lockObj )
|
|
|
+ {
|
|
|
+ table.Add( obj );
|
|
|
+ this.Save();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public void Update( T obj )
|
|
|
@@ -204,9 +213,12 @@ namespace OHV.SqliteDAL.DAL
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- table.Attach( obj );
|
|
|
- _context.Entry( obj ).State = EntityState.Modified;
|
|
|
- this.Save();
|
|
|
+ lock ( lockObj )
|
|
|
+ {
|
|
|
+ table.Attach( obj );
|
|
|
+ _context.Entry( obj ).State = EntityState.Modified;
|
|
|
+ this.Save();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public void Delete( object id )
|
|
|
@@ -215,29 +227,38 @@ namespace OHV.SqliteDAL.DAL
|
|
|
if ( existing == null )
|
|
|
return;
|
|
|
|
|
|
- if ( _context.Entry( existing ).State == EntityState.Detached )
|
|
|
+ lock ( lockObj )
|
|
|
{
|
|
|
- table.Attach( existing );
|
|
|
- }
|
|
|
+ if ( _context.Entry( existing ).State == EntityState.Detached )
|
|
|
+ {
|
|
|
+ table.Attach( existing );
|
|
|
+ }
|
|
|
|
|
|
- table.Remove( existing );
|
|
|
- this.Save();
|
|
|
+ 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 ( 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();
|
|
|
+ lock ( lockObj )
|
|
|
+ {
|
|
|
+ table.RemoveRange( table );
|
|
|
+ this.Save();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public void Save()
|