using System.Collections.Generic;
namespace System.Data.Fuse {
///
/// (from 'FUSE-fx.RepositoryContract')
/// A generic repository interface to decouple BL from persistence layers.
///
public interface IRepository where TEntity : class {
///
/// Returns an string, representing the "Identity" of the current origin.
/// This can be used to discriminate multiple source repos.
/// (usually it should be related to a SCOPE like {DbServer}+{DbName/Schema}+{EntityName})
/// NOTE: This is an technical disciminator and it is not required, that it is an human-readable
/// "frieldly-name". It can just be an Hash or Uid, so its NOT RECOMMENDED to use it as display label!
///
string GetOriginIdentity();
///
/// Returns an property bag which holds information about the implemented/supported capabilities of this IRepository.
///
///
RepositoryCapabilities GetCapabilities();
///
///
///
/// An array of field names to be used for sorting the results (before 'limit' and 'skip' is processed).
/// Use the character "^" as prefix for DESC sorting. Sample: ['^Age','Lastname']
///
///
///
///
EntityRef[] GetEntityRefs(
ExpressionTree filter, string[] sortedBy, int limit = 500, int skip = 0
);
///
/// NOTE: this method can only be used, if the 'SupportsStringBaseSearchExpressions'-Capability is given for this repository!
///
///
///
/// An array of field names to be used for sorting the results (before 'limit' and 'skip' is processed).
/// Use the character "^" as prefix for DESC sorting. Sample: ['^Age','Lastname']
///
///
///
///
EntityRef[] GetEntityRefsBySearchExpression(
string searchExpression, string[] sortedBy, int limit = 500, int skip = 0
);
///
/// Loads entity references by their keys, in exact order as the given key-array.
/// WARNING: the returned array will contain NULL entries for non-existing entities!
///
///
///
/// Returns an array with exact the same size as the given 'keysToLoad' array.
/// Non existing keys will be represented by a NULL entry at the corresponding position.
///
EntityRef[] GetEntityRefsByKey(
TKey[] keysToLoad
);
///
///
///
/// An array of field names to be used for sorting the results (before 'limit' and 'skip' is processed).
/// Use the character "^" as prefix for DESC sorting. Sample: ['^Age','Lastname']
///
///
///
///
TEntity[] GetEntities(
ExpressionTree filter, string[] sortedBy, int limit = 500, int skip = 0
);
///
/// NOTE: this method can only be used, if the 'SupportsStringBaseSearchExpressions'-Capability is given for this repository!
///
///
///
/// An array of field names to be used for sorting the results (before 'limit' and 'skip' is processed).
/// Use the character "^" as prefix for DESC sorting. Sample: ['^Age','Lastname']
///
///
///
///
TEntity[] GetEntitiesBySearchExpression(
string searchExpression, string[] sortedBy, int limit = 500, int skip = 0
);
///
/// Loads entities by their keys, in exact order as the given key-array.
/// WARNING: the returned array will contain NULL entries for non-existing entities!
///
///
///
/// Returns an array with exact the same size as the given 'keysToLoad' array.
/// Non existing keys will be represented by a NULL entry at the corresponding position.
///
TEntity[] GetEntitiesByKey(
TKey[] keysToLoad
);
///
///
///
/// An array of field names to be loaded
///
///
/// An array of field names to be used for sorting the results (before 'limit' and 'skip' is processed).
/// Use the character "^" as prefix for DESC sorting. Sample: ['^Age','Lastname']
///
///
///
///
Dictionary[] GetEntityFields(
ExpressionTree filter, string[] includedFieldNames, string[] sortedBy, int limit = 500, int skip = 0
);
///
/// NOTE: this method can only be used, if the 'SupportsStringBaseSearchExpressions'-Capability is given for this repository!
///
///
///
/// An array of field names to be loaded
///
///
/// An array of field names to be used for sorting the results (before 'limit' and 'skip' is processed).
/// Use the character "^" as prefix for DESC sorting. Sample: ['^Age','Lastname']
///
///
///
///
Dictionary[] GetEntityFieldsBySearchExpression(
string searchExpression, string[] includedFieldNames, string[] sortedBy, int limit = 500, int skip = 0
);
///
/// Loads entity fields by their keys, in exact order as the given key-array.
/// WARNING: the returned array will contain NULL entries for non-existing entities!
///
///
///
///
/// Returns an array with exact the same size as the given 'keysToLoad' array.
/// Non existing keys will be represented by a NULL entry at the corresponding position.
///
Dictionary[] GetEntityFieldsByKey(
TKey[] keysToLoad, string[] includedFieldNames
);
int CountAll();
int Count(ExpressionTree filter);
///
/// NOTE: this method can only be used, if the 'SupportsStringBaseSearchExpressions'-Capability is given for this repository!
///
///
///
int CountBySearchExpression(string searchExpression);
bool ContainsKey(TKey key);
///
/// Creates an new Entity or Updates the given set of fields for an entity and
/// returns all fields that ARE DIFFERENT from the given values or null, if the entity wasn't found.
///
///
/// NOTE: The target entity to be updated will be addressed by the key values used from this param,
/// so if the given dictionary contains key fields which are addressing an exisiting record, then it will be updated.
/// (CASE):
/// If the given dictionary contains NO key fields, then the result is depending on the concrete repository
/// implementation (see the 'RequiresExternalKeys'-Capability):
/// If external keys are required, this method will skip crating a record and return null,
/// otherwise it will create a new record (with an new key) and return it.
/// (CASE):
/// If the given dictionary contains key fields, which are addressing an NOT exisiting entity then the
/// result is again depending on the concrete repository implementation (see the 'RequiresExternalKeys'-Capability):
/// If external keys are required, this method will crate a record (using the given key) and return it,
/// otherwise it will skip create a new record (with an new key) and return it.
/// (CASE):
/// If the given dictionary contains key fields, which are addressing an NOT exisiting entity then
/// it will add it and return it again. Depending on the concrete repository implementation
/// (see the 'RequiresExternalKeys'-Capability) it will either use the given key oder create a assign
/// a new key that will be present within the returned fields). For that reason it is IMPORTANT,
/// that the call needs to evaluate the returned key!
///
/// All fields that ARE DIFFERENT from the given values or null, if the entity wasn't found.
/// NOTE: the returned entity can differ from the given one, because in some cases a field
/// (1) was not updated,
/// (2) was updated using normlized (=modified) value that differs from the given one,
/// (3) was updated implicitely (timestamp's,rowversion's,...)
Dictionary AddOrUpdateEntityFields(Dictionary fields);
///
/// Creates an new Entity or Updates the given set of fields for an entity and
/// returns the entity within its new state or null, if the entity wasn't found.
///
///
/// NOTE: The target entity to be updated will be addressed by the key values used from this param,
/// so if the given dictionary contains key fields which are addressing an exisiting record, then it will be updated.
/// (CASE):
/// If the given dictionary contains NO key fields, then the result is depending on the concrete repository
/// implementation (see the 'RequiresExternalKeys'-Capability):
/// If external keys are required, this method will skip crating a record and return null,
/// otherwise it will create a new record (with an new key) and return it.
/// (CASE):
/// If the given dictionary contains key fields, which are addressing an NOT exisiting entity then the
/// result is again depending on the concrete repository implementation (see the 'RequiresExternalKeys'-Capability):
/// If external keys are required, this method will crate a record (using the given key) and return it,
/// otherwise it will skip create a new record (with an new key) and return it.
/// (CASE):
/// If the given dictionary contains key fields, which are addressing an NOT exisiting entity then
/// it will add it and return it again. Depending on the concrete repository implementation
/// (see the 'RequiresExternalKeys'-Capability) it will either use the given key oder create a assign
/// a new key that will be present within the returned fields). For that reason it is IMPORTANT,
/// that the call needs to evaluate the returned key!
///
/// returns the entity within its new state or null, if the entity wasn't found.
/// NOTE: the returned entity can differ from the given one, because in some cases a field
/// (1) was not updated,
/// (2) was updated using normlized (=modified) value that differs from the given one,
/// (3) was updated implicitely (timestamp's,rowversion's,...)
TEntity AddOrUpdateEntity(TEntity entity);
///
/// Updates the given set of fields for an entity and
/// returns all fields that ARE DIFFERENT from the given values or null, if the entity wasn't found.
///
///
/// NOTE: The target entity to be updated will be addressed by the key values used from this param!
/// If the given dictionary does not contain the key fiels, an exception will be thrown!
///
/// All fields that ARE DIFFERENT from the given values or null, if the entity wasn't found.
/// NOTE: the returned entity can differ from the given one, because in some cases a field
/// (1) was not updated,
/// (2) was updated using normlized (=modified) value that differs from the given one,
/// (3) was updated implicitely (timestamp's,rowversion's,...)
Dictionary TryUpdateEntityFields(Dictionary fields);
///
/// Updates all updatable fields for an entity and
/// returns the entity within its new state or null, if the entity wasn't found.
///
///
/// NOTE: The target entity which to be updated will be addressed by the key values used from this param!
///
///
/// The entity after it was updated or null, if the entity wasn't found.
/// NOTE: the returned entity can differ from the given one, because in some cases a field
/// (1) was not updated,
/// (2) was updated using normlized (=modified) value that differs from the given one,
/// (3) was updated implicitely (timestamp's,rowversion's,...)
///
TEntity TryUpdateEntity(TEntity entity);
///
/// Adds an new entity and returns its Key on success, otherwise null
/// (also if the entity is already exisiting).
/// Depending on the concrete repository implementation the KEY properties
/// of the entity needs be pre-initialized (see the 'RequiresExternalKeys'-Capability).
///
///
/// The entity key on success, otherwise null
TKey TryAddEntity(TEntity entity);
///
/// Updates a dedicated subset of fields for all addressed entites and
/// returns an array containing the keys of affeced entities.
/// NOTE: this method can only be used, if the 'SupportsMassupdate'-Capability is given for this repository!
///
/// Keys for that entities, which sould be updated (non exisiting keys will be ignored).
/// A set of fields and value, that should be update.
/// It MUST NOT contain fields which are part of the Key, otherwise an exception will be thrown!
///
/// An array containing the keys of affeced entities.
TKey[] MassupdateByKeys(TKey[] keysToUpdate, Dictionary fields);
///
/// Updates a dedicated subset of fields for all addressed entites and
/// returns an array containing the keys of affeced entities.
/// NOTE: this method can only be used, if the 'SupportsMassupdate'-Capability is given for this repository!
///
/// A filter to adress that entities, which sould be updated.
/// A set of fields and value, that should be update.
/// It MUST NOT contain fields which are part of the Key, otherwise an exception will be thrown!
///
///
TKey[] Massupdate(ExpressionTree filter, Dictionary fields);
///
/// Updates a dedicated subset of fields for all addressed entites and
/// returns an array containing the keys of affeced entities.
/// NOTE: this method can only be used, if the 'SupportsStringBaseSearchExpressions'-Capability and the
/// 'SupportsMassupdate'-Capability are given for this repository!
///
/// A search expression to adress that entities, which sould be updated.
/// A set of fields and value, that should be update.
/// It MUST NOT contain fields which are part of the Key, otherwise an exception will be thrown!
///
///
TKey[] MassupdateBySearchExpression(string searchExpression, Dictionary fields);
///
/// Tries to delete entities by the given keys und returns an array containing the keys of only that entities
/// which were deleted successfully.
/// NOTE: this method can only be used, if the 'CanDeleteEntities'-Capability is given for this repository!
///
///
/// keys of deleted entities
TKey[] TryDeleteEntities(TKey[] keysToDelete);
///
/// Changes the KEY for an entity.
/// NOTE: this method can only be used, if the 'SupportsKeyUpdate'-Capability is given for this repository!
///
///
///
///
bool TryUpdateKey(TKey currentKey, TKey newKey);
}
}