|
|
@@ -71,27 +71,33 @@ namespace CD67.ModeleMVC.Factory.Internal
|
|
|
else return ObjectSet;
|
|
|
}
|
|
|
|
|
|
- public IQueryable<T> where(Expression<Func<T, bool>> expression, string sortParameter = null)
|
|
|
+ public virtual IQueryable<T> getManyBy(Expression<Func<T, bool>> expression, string sortParameter = null)
|
|
|
{
|
|
|
IQueryable<T> query = ObjectSet.Where(expression);
|
|
|
if (sortParameter != null) query = query.OrderBy(sortParameter);
|
|
|
return query;
|
|
|
}
|
|
|
|
|
|
- public IQueryable<T> where(string dynamicExpression, string sortParameter = null)
|
|
|
+ public virtual IQueryable<T> getManyBy(string dynamicExpression, string sortParameter = null)
|
|
|
{
|
|
|
IQueryable<T> query = ObjectSet.Where(dynamicExpression);
|
|
|
if (sortParameter != null) query = query.OrderBy(sortParameter);
|
|
|
return query;
|
|
|
}
|
|
|
|
|
|
- public void add(ref T entity)
|
|
|
+ public virtual void add(ref T entity)
|
|
|
{
|
|
|
ObjectSet.Add(entity);
|
|
|
dbContext.SaveChanges();
|
|
|
}
|
|
|
|
|
|
- public void update(ref T entity)
|
|
|
+ public virtual void addMany(ref List<T> entities)
|
|
|
+ {
|
|
|
+ ObjectSet.AddRange(entities);
|
|
|
+ dbContext.SaveChanges();
|
|
|
+ }
|
|
|
+
|
|
|
+ public virtual void update(ref T entity)
|
|
|
{
|
|
|
// On attache l'objet en paramètre au contexte, on le note bien comme modifié pour qu'il soit mis à jour
|
|
|
ObjectSet.Attach(entity);
|
|
|
@@ -99,11 +105,52 @@ namespace CD67.ModeleMVC.Factory.Internal
|
|
|
dbContext.SaveChanges();
|
|
|
}
|
|
|
|
|
|
- public void delete(ref T entity)
|
|
|
+ public virtual void updateMany(ref List<T> entities)
|
|
|
+ {
|
|
|
+ foreach (var item in entities)
|
|
|
+ {
|
|
|
+ // On attache l'objet en paramètre au contexte, on le note bien comme modifié pour qu'il soit mis à jour
|
|
|
+ ObjectSet.Attach(item);
|
|
|
+ dbContext.Entry(item).State = EntityState.Modified;
|
|
|
+ }
|
|
|
+ dbContext.SaveChanges();
|
|
|
+ }
|
|
|
+
|
|
|
+ public virtual void updateMany(Expression<Func<T, bool>> expression)
|
|
|
+ {
|
|
|
+ List<T> query = ObjectSet.Where(expression).ToList();
|
|
|
+ this.updateMany(ref query);
|
|
|
+ }
|
|
|
+
|
|
|
+ public virtual void updateMany(string dynamicExpression)
|
|
|
+ {
|
|
|
+ List<T> query = ObjectSet.Where(dynamicExpression).ToList();
|
|
|
+ this.updateMany(ref query);
|
|
|
+ }
|
|
|
+
|
|
|
+ public virtual void delete(ref T entity)
|
|
|
{
|
|
|
ObjectSet.Remove(entity);
|
|
|
dbContext.SaveChanges();
|
|
|
}
|
|
|
+
|
|
|
+ public virtual void deleteMany(ref List<T> entities)
|
|
|
+ {
|
|
|
+ ObjectSet.RemoveRange(entities);
|
|
|
+ dbContext.SaveChanges();
|
|
|
+ }
|
|
|
+
|
|
|
+ public virtual void deleteMany(Expression<Func<T, bool>> expression)
|
|
|
+ {
|
|
|
+ List<T> query = ObjectSet.Where(expression).ToList();
|
|
|
+ this.deleteMany(ref query);
|
|
|
+ }
|
|
|
+
|
|
|
+ public virtual void deleteMany(string dynamicExpression)
|
|
|
+ {
|
|
|
+ List<T> query = ObjectSet.Where(dynamicExpression).ToList();
|
|
|
+ this.deleteMany(ref query);
|
|
|
+ }
|
|
|
#endregion
|
|
|
|
|
|
#region Dispose
|