Class CustomServiceQueryExtender<T>
This class can be inherited by any custom code to provide a mechanism of creating queries that join across items without having to use separate IEntityRetriever queries.
As IEntityRetriever encapsulates the connection (web or direct database connection) for the client, this provides a mechanism to run LINQ queries regardless
Any class created inheriting from this can be called using ExecuteCustomQuery<T>(string, params object[]).
The constructed IQueryable should be compatible with dynamic Linq translations to SQL
Inheritance
Inherited Members
Namespace: LemonEdge.API.Core.Data
Assembly: LemonEdge.API.dll
Syntax
public abstract class CustomServiceQueryExtender<T> where T : IBaseEntity
Type Parameters
Name | Description |
---|---|
T | The type of item that is returned from executing this custom query |
Remarks
For example, we can use the following to create a query that looks at transactions and their postings:
public class GLPostingQueries : CustomServiceQueryExtender<API.Entities.IGLPosting>
{
public IQueryable<IGLPosting> GetGLPostingsAgainstInstruments(Guid[] instrumentIDs)
{
var trans = Helper.GetQueryableItems<API.Entities.ITransaction>().Where(x => x.InstrumentID.HasValue && instrumentIDs.Contains(x.InstrumentID.Value));
return from p in BaseItems
join t in trans on p.ParentTransactionID equals t.ID
select p;
}
}
Which we can call anywhere by using something similar to the following:
public class MyProcess
{
public Task<IEnumerable<IGLPosting>> GetPostings(IEntityRetriever context, Guid[] instrumentIDs) =>
context.ExecuteCustomQuery<IGLPosting>(nameof(GLPostingQueries.GetGLPostingsAgainstInstruments), new object[] { instrumentIDs });
}
Constructors
CustomServiceQueryExtender()
Declaration
protected CustomServiceQueryExtender()
Properties
BaseItems
The base set of IQueryable items to use within this query
Declaration
public IQueryable<T> BaseItems { get; set; }
Property Value
Type | Description |
---|---|
IQueryable<T> |
BaseItemsForType
Indicates the sub type to use for the item type if they are part of a replicated type such as Permissions
Declaration
public virtual Guid BaseItemsForType { get; }
Property Value
Type | Description |
---|---|
Guid |
Helper
An abstracted helper class that provides functionality to assist building your IQueryable query
Declaration
public ICustomServiceQueryHelper Helper { get; set; }
Property Value
Type | Description |
---|---|
ICustomServiceQueryHelper |
Methods
Init()
An initialization that allows you to preload any required data for the query itself, such as information from the local Cache using Cache
Declaration
public virtual Task Init()
Returns
Type | Description |
---|---|
Task | A task indicating the completion of the operation |