Interface IRepository<T>
Data repository (data object collection) type specific interface
Inherited Members
Namespace: XData
Assembly: XData.docfx.dll
Syntax
public interface IRepository<T> : IDataQuery<T>, IOrderedQueryable<T>, IQueryable<T>, IEnumerable<T>, IRepository, IDataQuery, IOrderedQueryable, IQueryable, IEnumerable, IDisposable where T : class, IDataObject
Type Parameters
Name | Description |
---|---|
T |
Remarks
Hint: Its possible to use any DI container with XData:
// example with Autofac syntax
// register
Container.Register(() => dataScope.GetRepository<Invoice>()).As<IRepository<Invoice>>();
Container.Register(() => dataScope.GetRepository<Invoice>().GetChild<InvoiceSpec>()).As<IRepository<InvoiceSpec>>();
// resolve
var spec = Container.Resolve<IRepository<InvoiceSpec>>(); //spec is linked with Invoice repository as a slave!
Properties
| Improve this Doc View SourceCurrent
Get/set current data object
Declaration
T Current { get; set; }
Property Value
Type | Description |
---|---|
T | Current data object instance |
Exceptions
Type | Condition |
---|---|
XDataQueryStructureException | object not mapped properly. |
Methods
| Improve this Doc View SourceAdd<TFrom>(IEnumerable<TFrom>, Mapping<TFrom, T>, DataSubmitFlag)
Copy objects from source repository
Declaration
bool Add<TFrom>(IEnumerable<TFrom> source, Mapping<TFrom, T> mapping = null, DataSubmitFlag flag = DataSubmitFlag.None)
where TFrom : class
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<TFrom> | source | Source repository |
Mapping<TFrom, T> | mapping | Data mapping |
DataSubmitFlag | flag | Submit flag |
Returns
Type | Description |
---|---|
Boolean | Success flag |
Type Parameters
Name | Description |
---|---|
TFrom |
Exceptions
Type | Condition |
---|---|
XDataRuntimeException | "source" parameter is null. |
XDataQueryStructureException | mapping error. |
See Also
Attach(T, DataObjectState, IEnumerable<KeyValuePair<String, Object>>, AttachedHandler<T>[])
Attach object to repository
Declaration
IRepository<T> Attach(T obj, DataObjectState state = DataObjectState.Original, IEnumerable<KeyValuePair<string, object>> originalValues = null, params AttachedHandler<T>[] handlers)
Parameters
Type | Name | Description |
---|---|---|
T | obj | Object instance |
DataObjectState | state | Object state |
IEnumerable<KeyValuePair<String, Object>> | originalValues | Original property values |
AttachedHandler<T>[] | handlers | Attached handlers |
Returns
Type | Description |
---|---|
IRepository<T> | Repository |
Remarks
Hint: Object attaching set Manual property to True automatically
Hint: The originalValues parameter can contain only necessary not null valued properties
Hint: Use SetValue<TKey, T>(TKey, T) to fill originalValues parameter
Hint: Use AttachedHandler<T> convert operators to attach object specific handlers
(SubmitObjectAttachedHandler<Invoice>)((ref Invoice i, DataSubmitFlag f) => true)
WARNING! Use repository SetAttachedHandlers(RepositoryAttachedHandler<T>[]) method to apply same handler for all objects!
Exceptions
Type | Condition |
---|---|
XDataQueryStructureException | no DataObjectAttribute found in data object mapping. |
XDataRuntimeException | type loading error. |
See Also
AttachNewObjects(IEnumerable<T>, AttachedHandler<T>[])
Attach object to repository
Declaration
IEnumerable<T> AttachNewObjects(IEnumerable<T> source, params AttachedHandler<T>[] handlers)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | source | Object sequence |
AttachedHandler<T>[] | handlers | Attached handlers |
Returns
Type | Description |
---|---|
IEnumerable<T> | Repository |
Remarks
Hint: Object attaching set Manual property to True automatically
Hint: The originalValues parameter can contain only necessary not null valued properties
Hint: Use SetValue<TKey, T>(TKey, T) to fill originalValues parameter
Hint: Use AttachedHandler<T> convert operators to attach object specific handlers
(SubmitObjectAttachedHandler<Invoice>)((ref Invoice i, DataSubmitFlag f) => true)
WARNING! Use repository SetAttachedHandlers(RepositoryAttachedHandler<T>[]) method to apply same handler for all objects!
Exceptions
Type | Condition |
---|---|
XDataQueryStructureException | no DataObjectAttribute found in data object mapping. |
XDataRuntimeException | type loading error. |
See Also
Clear(Expression<Func<T, Boolean>>, DataSubmitFlag)
Clear repository objects
Declaration
bool Clear(Expression<Func<T, bool>> predicate, DataSubmitFlag flag = DataSubmitFlag.None)
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<T, Boolean>> | predicate | |
DataSubmitFlag | flag |
Returns
Type | Description |
---|---|
Boolean |
Remarks
All objects corresponded current repository limitations will be deleted through single operation
WARNING! Trigger logic BeforeDelete and AfterDelete are not used in this case!
Use BeforeClear and AfterClear instead!
Exceptions
Type | Condition |
---|---|
XDataQueryStructureException | no DataObjectAttribute found in data object mapping. |
XDataRuntimeException | type loading error. |
ClearAttachedObjects()
Clear attached objects
Declaration
IRepository<T> ClearAttachedObjects()
Returns
Type | Description |
---|---|
IRepository<T> | Repository |
Remarks
WARNING! Clear attached objects NOT set Manual property to False automatically!
Exceptions
Type | Condition |
---|---|
XDataQueryStructureException | no DataObjectAttribute found in data object mapping. |
XDataRuntimeException | type loading error. |
Detach(Predicate<T>)
Detach virtual objects from repository
Declaration
IRepository<T> Detach(Predicate<T> predicate)
Parameters
Type | Name | Description |
---|---|---|
Predicate<T> | predicate | Object search predicate to detach |
Returns
Type | Description |
---|---|
IRepository<T> | Repository |
Exceptions
Type | Condition |
---|---|
XDataQueryStructureException | no DataObjectAttribute found in data object mapping. |
XDataRuntimeException | type loading error. |
See Also
Execute(String, IEnumerable<T>, IDictionary<String, Action<Byte[]>>, IDictionary<String, Func<Byte[], Byte[]>>)
Run custom logic over object instances
Declaration
bool Execute(string key, IEnumerable<T> objects, IDictionary<string, Action<byte[]>> post = null, IDictionary<string, Func<byte[], byte[]>> callback = null)
Parameters
Type | Name | Description |
---|---|---|
String | key | Logic key |
IEnumerable<T> | objects | Object instances |
IDictionary<String, Action<Byte[]>> | post | Post data handler |
IDictionary<String, Func<Byte[], Byte[]>> | callback | Callback handler |
Returns
Type | Description |
---|---|
Boolean | Success flag |
Exceptions
Type | Condition |
---|---|
XDataQueryStructureException | no DataObjectAttribute found in data object mapping. |
XDataRuntimeException | type loading error. |
See Also
GetChild<TChild>(Expression<Func<T, TChild[]>>, String, ISecuritySession, Variable[])
Get a child repository
Declaration
IRepository<TChild> GetChild<TChild>(Expression<Func<T, TChild[]>> property, string alias = null, ISecuritySession security = null, params Variable[] variables)
where TChild : class, IDataObject, new()
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<T, TChild[]>> | property | Property to store child entities |
String | alias | Child alias |
ISecuritySession | security | Security session |
Variable[] | variables | Child variables |
Returns
Type | Description |
---|---|
IRepository<TChild> | Repository |
Type Parameters
Name | Description |
---|---|
TChild | Child type |
Remarks
If child repository not exists it will be created and linked to base repository as a child
When alias parameter value is not set child object type name used as child repository alias
Exceptions
Type | Condition |
---|---|
XDataQueryStructureException | no DataObjectAttribute found in data object mapping. |
XDataRuntimeException | type loading error. |
See Also
| Improve this Doc View SourceGetChild<TChild>(Expression<Func<T, TChild>>, String, ISecuritySession, Variable[])
Get a child repository
Declaration
IRepository<TChild> GetChild<TChild>(Expression<Func<T, TChild>> property, string alias = null, ISecuritySession security = null, params Variable[] variables)
where TChild : class, IDataObject, new()
Parameters
Type | Name | Description |
---|---|---|
Expression<Func<T, TChild>> | property | Property to store child entity (1-to-1) |
String | alias | Child alias |
ISecuritySession | security | Security session |
Variable[] | variables | Child variables |
Returns
Type | Description |
---|---|
IRepository<TChild> | Repository |
Type Parameters
Name | Description |
---|---|
TChild | Child type |
Remarks
If child repository not exists it will be created and linked to base repository as a child
When alias parameter value is not set child object type name used as child repository alias
Exceptions
Type | Condition |
---|---|
XDataQueryStructureException | no DataObjectAttribute found in data object mapping. |
XDataRuntimeException | type loading error. |
See Also
| Improve this Doc View SourceLock(T)
Lock object in database
Declaration
bool Lock(T obj)
Parameters
Type | Name | Description |
---|---|---|
T | obj | Data object instance |
Returns
Type | Description |
---|---|
Boolean | Success flag |
Exceptions
Type | Condition |
---|---|
XDataRuntimeException | "obj" parameter is null. |
See Also
New()
Get new instance of data object
Declaration
T New()
Returns
Type | Description |
---|---|
T | Data object instance |
Exceptions
Type | Condition |
---|---|
XDataQueryStructureException | object not mapped properly. |
New(Action<T>[])
Get new instance of data object
Declaration
T New(params Action<T>[] init)
Parameters
Type | Name | Description |
---|---|---|
Action<T>[] | init | Data object initialization actions |
Returns
Type | Description |
---|---|
T | Data object instance |
Exceptions
Type | Condition |
---|---|
XDataQueryStructureException | object not mapped properly. |
Refresh(ref T)
Refresh object data from database
Declaration
bool Refresh(ref T obj)
Parameters
Type | Name | Description |
---|---|---|
T | obj | Data object instance |
Returns
Type | Description |
---|---|
Boolean | Success flag |
Exceptions
Type | Condition |
---|---|
XDataRuntimeException | "obj" parameter is null. |
XDataQueryStructureException | object not mapped properly. |
See Also
Reset()
Reset repository structure and filter values
Declaration
IRepository<T> Reset()
Returns
Type | Description |
---|---|
IRepository<T> | Self repository link |
Exceptions
Type | Condition |
---|---|
XDataQueryStructureException | no DataObjectAttribute found in data object mapping. |
XDataRuntimeException | type loading error. |
See Also
| Improve this Doc View SourceSetAttachedHandlers(ref T, AttachedHandler<T>[])
Attach extra handlers to single object
Declaration
void SetAttachedHandlers(ref T obj, params AttachedHandler<T>[] handlers)
Parameters
Type | Name | Description |
---|---|---|
T | obj | Object instance |
AttachedHandler<T>[] | handlers | Attached handlers |
Remarks
Hint: Use AttachedHandler<T> convert operators to attach object specific handlers
(SubmitObjectAttachedHandler<Invoice>)((ref Invoice i, DataSubmitFlag f) => true)
WARNING! Use repository SetAttachedHandlers(RepositoryAttachedHandler<T>[]) method to apply same handler for all objects!
Exceptions
Type | Condition |
---|---|
XDataQueryStructureException | no DataObjectAttribute found in data object mapping. |
XDataRuntimeException | type loading error. |
See Also
SetAttachedHandlers(RepositoryAttachedHandler<T>[])
Attach extra handlers to repository
Declaration
IRepository<T> SetAttachedHandlers(params RepositoryAttachedHandler<T>[] handlers)
Parameters
Type | Name | Description |
---|---|---|
RepositoryAttachedHandler<T>[] | handlers | Attached handlers |
Returns
Type | Description |
---|---|
IRepository<T> | Repository |
Remarks
Hint: Use RepositoryAttachedHandler<T> convert operators to attach object specific handlers
(SubmitObjectAttachedHandler<Invoice>)((ref Invoice i, DataSubmitFlag f) => true)
Exceptions
Type | Condition |
---|---|
XDataQueryStructureException | no DataObjectAttribute found in data object mapping. |
XDataRuntimeException | type loading error. |
SetFilterValue(RuntimeFilter, Object)
Set metadata defined RuntimeFilter value
Declaration
IRepository<T> SetFilterValue(RuntimeFilter filter, object val)
Parameters
Type | Name | Description |
---|---|---|
RuntimeFilter | filter | Filter |
Object | val | Filter value |
Returns
Type | Description |
---|---|
IRepository<T> | Self repository link |
Remarks
Hint: Set val = null
to clear filter
Exceptions
Type | Condition |
---|---|
XDataRuntimeException | "filter" parameter is null. |
See Also
| Improve this Doc View SourceSubmit(ref T, DataSubmitFlag)
Save single data object changes
Declaration
bool Submit(ref T obj, DataSubmitFlag flag = DataSubmitFlag.None)
Parameters
Type | Name | Description |
---|---|---|
T | obj | Data object instance |
DataSubmitFlag | flag | Submit flag |
Returns
Type | Description |
---|---|
Boolean | Success flag |
Exceptions
Type | Condition |
---|---|
XDataRuntimeException | "objects" is null. |
See Also
| Improve this Doc View SourceSubmit(IEnumerable<T>, DataSubmitFlag)
Save multiple data objects changes
Declaration
bool Submit(IEnumerable<T> objects, DataSubmitFlag flag = DataSubmitFlag.None)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | objects | Data object sequence |
DataSubmitFlag | flag | Submit flag |
Returns
Type | Description |
---|---|
Boolean | Success flag |
Exceptions
Type | Condition |
---|---|
XDataRuntimeException | "objects" is null or empty sequence. |
See Also
Events
| Improve this Doc View SourceOnCurrentObjectChanged
Event fired when repository current object is changed
Declaration
event CurrentObjectChanged<T> OnCurrentObjectChanged
Event Type
Type | Description |
---|---|
CurrentObjectChanged<T> |
Exceptions
Type | Condition |
---|---|
XDataRuntimeException | custom logic fires exception. |
OnCurrentObjectChanging
Event fired when repository current object changing occurred
Declaration
event CurrentObjectChanging<T> OnCurrentObjectChanging
Event Type
Type | Description |
---|---|
CurrentObjectChanging<T> |
Exceptions
Type | Condition |
---|---|
XDataRuntimeException | custom logic fires exception. |
OnInit
Event fired when repository is initialized
Declaration
event InitRepository<T> OnInit
Event Type
Type | Description |
---|---|
InitRepository<T> |
Exceptions
Type | Condition |
---|---|
XDataRuntimeException | custom logic fires exception. |
OnInitObject
Event fired when object is initialized
Declaration
event InitObject<T> OnInitObject
Event Type
Type | Description |
---|---|
InitObject<T> |
Exceptions
Type | Condition |
---|---|
XDataRuntimeException | custom logic fires exception. |
OnInvalidate
Event fired when repository need to be refreshed
Declaration
event InvalidateRepository<T> OnInvalidate
Event Type
Type | Description |
---|---|
InvalidateRepository<T> |
Exceptions
Type | Condition |
---|---|
XDataRuntimeException | custom logic fires exception. |
OnInvalidateObject
Event fired when object need to be refreshed
Declaration
event InvalidateObject<T> OnInvalidateObject
Event Type
Type | Description |
---|---|
InvalidateObject<T> |
Exceptions
Type | Condition |
---|---|
XDataRuntimeException | custom logic fires exception. |