|
|
@ -2,6 +2,7 @@
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
|
|
|
|
using System.Security.Cryptography.X509Certificates;
|
|
|
|
using Marr.Data;
|
|
|
|
using Marr.Data;
|
|
|
|
using Marr.Data.QGen;
|
|
|
|
using Marr.Data.QGen;
|
|
|
|
using NzbDrone.Core.Datastore.Events;
|
|
|
|
using NzbDrone.Core.Datastore.Events;
|
|
|
@ -142,23 +143,44 @@ namespace NzbDrone.Core.Datastore
|
|
|
|
|
|
|
|
|
|
|
|
public void InsertMany(IList<TModel> models)
|
|
|
|
public void InsertMany(IList<TModel> models)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
using (var unitOfWork = new UnitOfWork(() => DataMapper))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
unitOfWork.BeginTransaction();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var model in models)
|
|
|
|
foreach (var model in models)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Insert(model);
|
|
|
|
unitOfWork.DB.Insert(model);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unitOfWork.Commit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void UpdateMany(IList<TModel> models)
|
|
|
|
public void UpdateMany(IList<TModel> models)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
using (var unitOfWork = new UnitOfWork(() => DataMapper))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
unitOfWork.BeginTransaction();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var model in models)
|
|
|
|
foreach (var model in models)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Update(model);
|
|
|
|
var localModel = model;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (model.Id == 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw new InvalidOperationException("Can't update model with ID 0");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unitOfWork.DB.Update(model, c => c.Id == localModel.Id);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unitOfWork.Commit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void DeleteMany(List<TModel> models)
|
|
|
|
public void DeleteMany(List<TModel> models)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
models.ForEach(Delete);
|
|
|
|
DeleteMany(models.Select(m => m.Id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public TModel Upsert(TModel model)
|
|
|
|
public TModel Upsert(TModel model)
|
|
|
@ -179,7 +201,19 @@ namespace NzbDrone.Core.Datastore
|
|
|
|
|
|
|
|
|
|
|
|
public void DeleteMany(IEnumerable<int> ids)
|
|
|
|
public void DeleteMany(IEnumerable<int> ids)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ids.ToList().ForEach(Delete);
|
|
|
|
using (var unitOfWork = new UnitOfWork(() => DataMapper))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
unitOfWork.BeginTransaction();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var id in ids)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var localId = id;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unitOfWork.DB.Delete<TModel>(c => c.Id == localId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unitOfWork.Commit();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Purge()
|
|
|
|
public void Purge()
|
|
|
|