DataServices

This is the base clase for DataService classes that implements IDataServices.

Namespace:
Inetdev.Data
Type:
Class
Public:
Yes
Protected:
No
Sealed:
No
Abstract:
Yes
Inherits from:
System.Object
Implements:
Inetdev.Data.IDataServices

Constructors

DataServices

Default constructor

Signature:
protected Void DataServices()

Properties

Alias

Get the alias of the database table.

Signature:
public String Alias { get; set; }

CommandBuilder

Get or set the engine service command builder.

Signature:
public IDbCmdBuilder CommandBuilder { get; set; }

DataAccessAPI

Get or set the DataAccess interface object.

Signature:
public IDbAccess DataAccessAPI { get; set; }

DataModelAuditor

Get or set the data update logger object.

Signature:
public IDataModelAuditor DataModelAuditor { get; set; }

DataModelCmdBuilder

Get or set the SQL builder object.

Signature:
public IDataModelCmdBuilder DataModelCmdBuilder { get; set; }

Fields

Get a list that contains the definition of table fields.

Signature:
public IDictionary<String, Field> Fields { get; set; }

Schema

Get or set the schema or owner of database objects.

Signature:
public String Schema { get; set; }

SequenceName

Get or set the name of the sequence to use.

Signature:
public String SequenceName { get; set; }

StringToDbTypeConverter

Converts string to object of a specified DbType.

Signature:
public IStringToDbTypeConverter StringToDbTypeConverter { get; set; }

Table

Get the table name.

Signature:
public String Table { get; set; }

Methods

AppendFilterTerms

Appends to the where clause all set terms.

Signature:
public Void AppendFilterTerms(statement, terms, match)
Parameters
Name Type Summary
statement Statement Statement to add terms.
terms List<Term> A collections of terms.
match MatchKind How to match the terms.
Exceptions
Type Summary
ArgumentNullException Thrown when statement is null.
ArgumentNullException Thrown when terms is null.
InvalidTermColumnNameException Thrown when a term.Column name does not exists within the fields collection.

AppendStaticTerms

Appends to the where clause all set static terms.

Signature:
public Void AppendStaticTerms(statement, terms)
Parameters
Name Type Summary
statement Statement Statement to add terms.
terms List<StaticTerm> A collections of terms.
Exceptions
Type Summary
ArgumentNullException Thrown when statement is null.
ArgumentNullException Thrown when terms is null.
InvalidTermColumnNameException Thrown when a term.Column name does not exists within the fields collection.

BuildModelList

Builds a list of domain model objects of dataModelType from the specified reader.

Signature:
protected IEnumerable<IDataModel> BuildModelList(dataModelType, reader)
Returns

A list of domain model objects.

Parameters
Name Type Summary
dataModelType Type Type of the domain model object to retrieve.
reader IDataReader The data reader containing the database data.
Exceptions
Type Summary
ArgumentNullException Thrown when dataModelType is null.
ArgumentNullException Thrown when reader is null.

BuildModelList

Builds a list of domain model objects of dataModelType from the specified reader.

Signature:
protected IEnumerable<IDataModel> BuildModelList(dataModelType, reader, parent)
Returns

A list of domain model objects.

Parameters
Name Type Summary
dataModelType Type Type of the domain model object to retrieve.
reader IDataReader The data reader containing the database data.
parent IDataModel Parent object of the model being constructed.
Exceptions
Type Summary
ArgumentNullException Thrown when dataModelType is null.
ArgumentNullException Thrown when reader is null.

BuildModelList

Builds a list of domain model objects of from the specified SelectStatement.

Signature:
protected IEnumerable BuildModelList<T>(statement)
Returns

A list of domain model objects.

Parameters
Name Type Summary
statement SelectStatement The SelectStatement to excecute.
Exceptions
Type Summary
ArgumentNullException Thrown where statement is null.

BuildModelList

Builds a list of domain model objects of from the specified SelectStatement.

Signature:
protected IEnumerable BuildModelList<T>(statement, parent)
Returns

A list of domain model objects.

Parameters
Name Type Summary
statement SelectStatement The SelectStatement to excecute.
parent IDataModel The parent object of the model being constructed.
Exceptions
Type Summary
ArgumentNullException Thrown where statement is null.

BuildModelListAsync

Builds a list of domain model objects of from the specified SelectStatement.

Signature:
protected Task<IEnumerable> BuildModelListAsync<T>(statement)
Returns

A list of domain model objects.

Parameters
Name Type Summary
statement SelectStatement The SelectStatement to excecute.
Exceptions
Type Summary
ArgumentNullException Thrown where statement is null.

BuildModelListAsync

Builds a list of domain model objects of from the specified SelectStatement.

Signature:
protected Task<IEnumerable> BuildModelListAsync<T>(statement, parent)
Returns

A list of domain model objects.

Parameters
Name Type Summary
statement SelectStatement The SelectStatement to excecute.
parent IDataModel The parent object of the model being constructed.
Exceptions
Type Summary
ArgumentNullException Thrown where statement is null.

Delete

Deletes a record from the underlaying data source.

Signature:
public Int32 Delete(model, timestampKind, expectedTimestamp)
Returns

Amount of records affected.

Parameters
Name Type Summary
model IDataModel The object to delete.
timestampKind TimestampKind Kind of timestamp to apply on the WHERE clause.
expectedTimestamp DateTime Timestamp that is expected to be on the database.
Exceptions
Type Summary
ArgumentNullException Thrown when the model is null.
ConcurrectActionMissedException Thrown when no record was affected and a timestamp kind was specified.
AuditingException Thrown when an auditing process fails or cannot be completed successfully.

DeleteAsync

Deletes a record from the underlaying data source.

Signature:
public Task<Int32> DeleteAsync(model, timestampKind, expectedTimestamp)
Parameters
Name Type Summary
model IDataModel The object to delete.
timestampKind TimestampKind Kind of timestamp to apply on the WHERE clause.
expectedTimestamp DateTime Timestamp that is expected to be on the database.
Exceptions
Type Summary
ArgumentNullException Thrown when the model is null.
ConcurrectActionMissedException Thrown when no record was affected and a timestamp kind was specified.
AuditingException Thrown when an auditing process fails or cannot be completed successfully.

EnsureObjectState

Ensures that this object has a valid state.

Signature:
protected Void EnsureObjectState()
Exceptions
Type Summary
MissingRequiredPropertyException Thrown when a required property is not initialized.

EnumerateModel

Enumerates an IDataModel of from the specified reader.

Signature:
protected IEnumerable EnumerateModel<T>(reader)
Returns

An enumeration of IDataModel of .

Parameters
Name Type Summary
reader IDataReader An IDataReader with the database data.
Exceptions
Type Summary
ArgumentNullException Thrown when reader is null.

EnumerateModel

Enumerates an IDataModel of from the specified reader.

Signature:
protected IEnumerable EnumerateModel<T>(reader, parent)
Returns

An enumeration of IDataModel of .

Parameters
Name Type Summary
reader IDataReader An IDataReader with the database data.
parent IDataModel Parent object of the model beeing constructed.
Exceptions
Type Summary
ArgumentNullException Thrown when reader is null.

GetModel

Gets a domain model object of dataModelType looking for it's primary key.

Signature:
public IDataModel GetModel(dataModelType, model)
Returns

An initialized data model object.

Parameters
Name Type Summary
dataModelType Type The Type of the domain model object to retrieve.
model IDataModel An IDataModel holding the primary key to look for.
Exceptions
Type Summary
ArgumentNullException

Thrown when dataModelType is null.

-or-

Thrown when model is null.

MissingRequiredPropertyException Thrown when the this data service object was not properly initialized.
DataServiceOperationNotSupportedException Thrown when the repository does not have a primary key column.

GetModel

Gets a model object of type looking for it primary key in the underlying repository.

Signature:
public GetModel<T>(model)
Returns

An initialized data model object.

Parameters
Name Type Summary
model T An instance of the model object with the primary key data.
Exceptions
Type Summary
ArgumentNullException Thrown when model is null.
MissingRequiredPropertyException Thrown when a required property is not initialized.
DataServiceOperationNotSupportedException Thrown when the repository does not have a primary key column.

GetModelAsync

Gets a domain model object of dataModelType looking for it's primary key.

Signature:
public Task<IDataModel> GetModelAsync(dataModelType, model)
Returns

An initialized data model object.

Parameters
Name Type Summary
dataModelType Type The Type of the domain model object to retrieve.
model IDataModel An IDataModel holding the primary key to look for.
Exceptions
Type Summary
ArgumentNullException

Thrown when dataModelType is null.

-or-

Thrown when model is null.

MissingRequiredPropertyException Thrown when the this data service object was not properly initialized.
DataServiceOperationNotSupportedException Thrown when the repository does not have a primary key column.

GetModelAsync

Gets a model object of type looking for it primary key in the underlying repository.

Signature:
public Task GetModelAsync<T>(model)
Returns

An initialized data model object.

Parameters
Name Type Summary
model T An instance of the model object with the primary key data.
Exceptions
Type Summary
ArgumentNullException Thrown when model is null.
MissingRequiredPropertyException Thrown when a required property is not initialized.
DataServiceOperationNotSupportedException Thrown when the repository does not have a primary key column.

GetModelByIdentity

Gets a domain model object of dataModelType looking for it's identity property.

Signature:
public IDataModel GetModelByIdentity(dataModelType, model)
Returns

An initialized data model object.

Parameters
Name Type Summary
dataModelType Type The Type of the domain model object to retrieve.
model IDataModel An IDataModel holding the identity to look for.
Exceptions
Type Summary
ArgumentNullException

Thrown when dataModelType is null.

-or-

Thrown when model is null.

MissingRequiredPropertyException Thrown when the this data service object was not properly initialized.
DataServiceOperationNotSupportedException Thrown when the repository does not have a primary key column.

GetModelByIdentity

Gets a model object of type looking for the identity field in the underlying table.

Signature:
public GetModelByIdentity<T>(model)
Returns

An initialized data model object.

Parameters
Name Type Summary
model T An instance of the model object with the identity data.
Exceptions
Type Summary
ArgumentNullException Thrown when model is null.
MissingRequiredPropertyException Thrown when a required property is not initialized.
DataServiceOperationNotSupportedException Thrown when the repository does not have a primary key column.

GetModelByIdentityAsync

Gets a domain model object of dataModelType looking for it's identity property.

Signature:
public Task<IDataModel> GetModelByIdentityAsync(dataModelType, model)
Returns

An initialized data model object.

Parameters
Name Type Summary
dataModelType Type The Type of the domain model object to retrieve.
model IDataModel An IDataModel holding the identity to look for.
Exceptions
Type Summary
ArgumentNullException

Thrown when dataModelType is null.

-or-

Thrown when model is null.

MissingRequiredPropertyException Thrown when the this data service object was not properly initialized.
DataServiceOperationNotSupportedException Thrown when the repository does not have a primary key column.

GetModelByIdentityAsync

Gets a model object of type looking for the identity field in the underlying table.

Signature:
public Task GetModelByIdentityAsync<T>(model)
Returns

An initialized data model object.

Parameters
Name Type Summary
model T An instance of the model object with the identity data.
Exceptions
Type Summary
ArgumentNullException Thrown when model is null.
MissingRequiredPropertyException Thrown when a required property is not initialized.
DataServiceOperationNotSupportedException Thrown when the repository does not have a primary key column.

GetRowByIdentityStatement

Builds a SelectStatement that retrives a record looking by identity.

Signature:
protected SelectStatement GetRowByIdentityStatement(model)
Returns

A SelectStatement to execute.

Parameters
Name Type Summary
model IDataModel An IDataModel that holds the identity.
Exceptions
Type Summary
ArgumentNullException Thrown when model is null.
DataServiceOperationNotSupportedException Thrown when the repository does not have an Identity column.

GetRowByPrimaryKeyStatement

Builds a SelectStatement that retrives a record looking by primary key.

Signature:
protected SelectStatement GetRowByPrimaryKeyStatement(model)
Returns

A SelectStatement to execute.

Parameters
Name Type Summary
model IDataModel An IDataModel that holds the primary key.
Exceptions
Type Summary
ArgumentNullException Thrown when model is null.
DataServiceOperationNotSupportedException Thrown when the repository does not have a primary key column.

Insert

Insert a record into the underlaying data source

Signature:
public Int32 Insert(model)
Returns

Amount of records affected

Parameters
Name Type Summary
model IDataModel The object to insert
Exceptions
Type Summary
ArgumentNullException Thrown when the model is null.
AuditingException Thrown when an auditing process fails or cannot be completed successfully.

InsertAsync

Insert a record into the underlaying data source

Signature:
public Task<Int32> InsertAsync(model)
Parameters
Name Type Summary
model IDataModel The object to insert
Exceptions
Type Summary
ArgumentNullException Thrown when the model is null.
AuditingException Thrown when an auditing process fails or cannot be completed successfully.

RunCountStatement

Run a count statement and returns the count.

Signature:
protected Int32 RunCountStatement(statement)
Parameters
Name Type Summary
statement SelectStatement The statement to run.
Exceptions
Type Summary
ArgumentNullException Thrown where statement is null.

RunCountStatementAsync

Run a count statement and returns the count.

Signature:
protected Task<Int32> RunCountStatementAsync(statement)
Parameters
Name Type Summary
statement SelectStatement The statement to run.
Exceptions
Type Summary
ArgumentNullException Thrown where statement is null.

SanitizePageNumber

Calculates the maximum page number and returns the specified page or the maximun page number if page is not valid.

Signature:
protected Int32 SanitizePageNumber(page, pageLength, totalItems)
Returns

A sanitized page number.

Parameters
Name Type Summary
page Int32 Attempted page number.
pageLength Int32 Page length.
totalItems Int32 Total items.

Update

Updates a record in the underlaying data source

Signature:
public Int32 Update(model, timestampKind, expectedTimestamp)
Returns

Amount of records affected

Parameters
Name Type Summary
model IDataModel The object to update
timestampKind TimestampKind Kind of timestamp to apply on the WHERE clause.
expectedTimestamp DateTime Timestamp that is expected to be on the database.
Exceptions
Type Summary
ArgumentNullException Thrown when the model is null.
ConcurrectActionMissedException Thrown when no record was affected and a timestamp kind was specified.
AuditingException Thrown when an auditing process fails or cannot be completed successfully.

UpdateAsync

Updates a record in the underlaying data source

Signature:
public Task<Int32> UpdateAsync(model, timestampKind, expectedTimestamp)
Returns

Amount of records affected

Parameters
Name Type Summary
model IDataModel The object to update
timestampKind TimestampKind Kind of timestamp to apply on the WHERE clause.
expectedTimestamp DateTime Timestamp that is expected to be on the database.
Exceptions
Type Summary
ArgumentNullException Thrown when the model is null.
ConcurrectActionMissedException Thrown when no record was affected and a timestamp kind was specified.
AuditingException Thrown when an auditing process fails or cannot be completed successfully.