using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using xModels.Base;
using xModels.Dtos;
namespace xDataService.Interfaces {
///
/// a Base Repository Interface for Manipulate
/// an Entity in DataBase
///
///
public interface IXBaseRepository : IDisposable
where T : XBaseEntity {
//
#region Add ...
///
/// add a new Entity ...
///
///
///
///
Task AddAsync (
T item,
bool saveChanges = true
);
///
/// add or update an Entity (add if not exists/update if exists) ...
///
///
///
///
Task AddOrUpdateAsync (
T item,
bool saveChanges = true
);
///
/// add a range of new Entities ...
///
///
///
///
Task AddRangeAsync (
IEnumerable items,
bool saveChanges = true
);
#endregion
//
#region Remove ...
///
/// remove an Entity by it's Id ...
///
///
///
///
///
Task RemoveAsync (
TKey id,
bool softDelete = true,
bool saveChanges = true
);
///
/// remove an Entity ...
///
///
///
///
///
Task RemoveAsync (
T item,
bool softDelete = true,
bool saveChanges = true
);
///
/// remove a range of exists Entities ...
///
///
///
///
///
Task RemoveRangeAsync (
IEnumerable items,
bool softDelete = true,
bool saveChanges = true
);
#endregion
//
#region Retrieve ...
///
/// retrieve whole items as queryable ...
///
///
IQueryable AsQueryable ();
///
/// retrieve an Entity by it's Id ...
///
///
///
///
///
Task GetAsync (
TKey id,
bool ignoreSoftDeleteds = true,
bool containsDetail = false
);
///
/// retrieve all exists Entities ...
///
///
///
///
Task> GetAllAsync (
bool ignoreSoftDeleteds = true,
bool containsDetail = false
);
///
/// find an Entity by providing a Conditional Expression ...
///
///
///
///
///
Task FindOneAsync (
Expression> whereClause,
bool ignoreSoftDeleteds = true,
bool containsDetail = false
);
///
/// find a collection of Entities by proving a Conditional Expression ...
///
///
///
///
///
Task> FindManyAsync (
Expression> whereClause,
bool ignoreSoftDeleteds = true,
bool containsDetail = false
);
///
/// retrieve Entities based on XQuery Pagination structure ...
///
///
///
///
Task> QueryAsync (
XQuery query,
bool ignoreSoftDeleteds = true
);
///
/// retrieve Entities based on XQuery Pagination structure by providing a Conditional Expression ...
///
///
///
///
///
Task> ConditionalQueryAsync (
Expression> whereClause,
XQuery query,
bool ignoreSoftDeleteds = true
);
#endregion
//
#region Update ...
///
/// Update an Entity values ...
///
///
///
///
///
Task UpdateAsync (
TKey id,
T item,
bool saveChanges = true
);
///
/// Update a range of Entities ...
///
///
///
///
Task UpdateRangeAsync (
IEnumerable items,
bool saveChanges = true
);
#endregion
//
#region Count ...
///
/// count all exists Entities ...
///
///
///
Task CountAsync (bool ignoreSoftDeleteds = true);
///
/// count all exists Entities Pages by providing page size ...
///
///
///
///
Task PagesCountAsync (
int pageSize,
int? totalItems = null
);
#endregion
//
#region Exists ...
///
/// Check an Entity exists or not ...
///
///
///
///
Task IsExistsAsync (
TKey id,
bool ignoreSoftDeleteds = true
);
#endregion
//
#region Unit Of Work ...
///
/// Save all unsaved Transactions on DbContext ...
/// used fo Unit Of Works Design Pattern ...
///
///
Task SaveChangesAsync ();
#endregion
//
#region Key ...
TKey GetKey (T item);
void SetKey (
ref T item,
TKey id
);
Task HandleKeyAsync (T item);
#endregion
//
#region Detach ...
void Detach (T item);
void Detach (IEnumerable items);
void Detach (XQueryResult query);
void Detach (XPageResponse page);
#endregion
}
}