Try our conversational search powered by Generative AI!

Class GenericDataSource<TObject, TCollection, TKey>

Generic implementation of a DataSourceControl

Implements
Namespace: EPiServer.Web.WebControls
Assembly: EPiServer.Cms.AspNet.dll
Version: 11.20.7
Syntax
public abstract class GenericDataSource<TObject, TCollection, TKey> : DataSourceControl, IDataSourceMethods where TCollection : IList, IEnumerable, new()
Type Parameters
Name Description
TObject

Business object type

TCollection

Business object collection type

TKey

Business object primary key type

Constructors

GenericDataSource()

Declaration
protected GenericDataSource()

Properties

CanDelete

Gets a value indicating whether a DataSource supports instance deletion.

Declaration
protected virtual bool CanDelete { get; }
Property Value
Type Description
System.Boolean

CanInsert

Gets a value indicating whether a DataSource supports instance inserts.

Declaration
protected virtual bool CanInsert { get; }
Property Value
Type Description
System.Boolean

CanUpdate

Gets a value indicating whether a DataSource supports instance updates.

Declaration
protected virtual bool CanUpdate { get; }
Property Value
Type Description
System.Boolean

DeleteParameters

Gets the parameters collection that contains the parameters that are used when deleting tabDefinition.

Declaration
public ParameterCollection DeleteParameters { get; }
Property Value
Type Description
System.Web.UI.WebControls.ParameterCollection

InsertIndex

Gets or sets an index to be used as position for insertion of a new instance in a GridView insertion. Setting this property to anything other than -1 will set the data source in insertion state. The insertion state terminates when Update is performed on the data source or when this property is set to -1 explicitly.

Declaration
public int InsertIndex { get; set; }
Property Value
Type Description
System.Int32

InsertParameters

Gets the parameters collection that contains the parameters that are used when inserting tabDefinition.

Declaration
public ParameterCollection InsertParameters { get; }
Property Value
Type Description
System.Web.UI.WebControls.ParameterCollection

KeyName

Gets the name of the instance field that will be used as the primary key. Override this property to return a name that differs from the default primary key name "ID".

Declaration
protected virtual string KeyName { get; }
Property Value
Type Description
System.String

Method

Gets or sets the method to be used

Declaration
protected DataSourceMethod Method { get; set; }
Property Value
Type Description
DataSourceMethod

The method.

ParameterValues

Contains the parameters for operations

Declaration
public IDictionary ParameterValues { get; }
Property Value
Type Description
System.Collections.IDictionary

The parameter values.

SelectParameters

Gets the parameters collection that contains the parameters that are used when selecting tabDefinition.

Declaration
public ParameterCollection SelectParameters { get; }
Property Value
Type Description
System.Web.UI.WebControls.ParameterCollection

UpdateParameters

Gets the parameters collection that contains the parameters that are used when updating tabDefinition.

Declaration
public ParameterCollection UpdateParameters { get; }
Property Value
Type Description
System.Web.UI.WebControls.ParameterCollection

View

Gets the current data source view for the data source.

Declaration
protected virtual GenericDataSourceView<GenericDataSource<TObject, TCollection, TKey>> View { get; }
Property Value
Type Description
GenericDataSourceView<GenericDataSource<TObject, TCollection, TKey>>

Methods

CreateItem(List<TObject>)

Override to provide new instance of the business object.

Declaration
protected abstract TObject CreateItem(List<TObject> items)
Parameters
Type Name Description
System.Collections.Generic.List<TObject> items

the list of current instances in the given scope.

Returns
Type Description
TObject

Delete(IDictionary)

Called by the GenericDataSourceView when the bound control has requested a deletion of an instance.

Declaration
public virtual int Delete(IDictionary values)
Parameters
Type Name Description
System.Collections.IDictionary values

The parameters that specifies the instance to delete.

Returns
Type Description
System.Int32

DeleteItem(TObject)

Override to handle deletion of an item.

Declaration
protected abstract void DeleteItem(TObject item)
Parameters
Type Name Description
TObject item

The item to delete.

GetView(String)

Returns the view corresponding to given name, only supported view is DefaultView.

Declaration
protected override DataSourceView GetView(string viewName)
Parameters
Type Name Description
System.String viewName

The name of the view

Returns
Type Description
System.Web.UI.DataSourceView

The corresponding DataSourceView

Insert(IDictionary)

Called by the GenericDataSourceView when the bound control has requested to insert a new instance.

Declaration
public virtual int Insert(IDictionary values)
Parameters
Type Name Description
System.Collections.IDictionary values

The parameters that specifies

Returns
Type Description
System.Int32

IsValid(TObject, ref String)

When overridden, provides validation of an item.

Declaration
protected virtual bool IsValid(TObject item, ref string message)
Parameters
Type Name Description
TObject item

the item to validate.

System.String message

set this parameter to provide a information about why validation failed.

Returns
Type Description
System.Boolean

true when the item is valid, otherwise false.

ListItems()

Override to return a list of instances.

Declaration
protected abstract List<TObject> ListItems()
Returns
Type Description
System.Collections.Generic.List<TObject>

a list of instances.

LoadItem(TKey)

Override to load an item with the specified key.

Declaration
protected abstract TObject LoadItem(TKey key)
Parameters
Type Name Description
TKey key

The key of the instance to load.

Returns
Type Description
TObject

A object instance.

OnInit(EventArgs)

Raises the System.Web.UI.Control.Init event.

Declaration
protected override void OnInit(EventArgs e)
Parameters
Type Name Description
System.EventArgs e

An System.EventArgs object that contains the event data.

SaveItem(TObject)

Override to handle persisting of an item.

Declaration
protected abstract void SaveItem(TObject item)
Parameters
Type Name Description
TObject item

The item to persist.

Select(DataSourceSelectArguments)

Called by the GenericDataSouceView to retreive an enumeration of instances. Override this method to extend the functionality e.g. paging support.

Declaration
public virtual IEnumerable Select(DataSourceSelectArguments arguments)
Parameters
Type Name Description
System.Web.UI.DataSourceSelectArguments arguments

arguments specifying the query

Returns
Type Description
System.Collections.IEnumerable

SetupParameters(IDictionary)

When overriden, provides ways to manipulate the parameter dictionary used for setting up the state of instance prior to saving it.

Declaration
protected virtual void SetupParameters(IDictionary values)
Parameters
Type Name Description
System.Collections.IDictionary values

Dictionary of properties to be used for setting the state of an instance.

ToCollection(List<TObject>)

Converts a generic list to a strongly typed collection

Declaration
public static TCollection ToCollection(List<TObject> list)
Parameters
Type Name Description
System.Collections.Generic.List<TObject> list

The list to convert

Returns
Type Description
TCollection

ToList(TCollection)

Converts a strongly typed collection to a generic list

Declaration
public static List<TObject> ToList(TCollection collection)
Parameters
Type Name Description
TCollection collection

The collection to convert

Returns
Type Description
System.Collections.Generic.List<TObject>

Update(IDictionary)

Called by the GenericDataSourceView when the bound control has requested an update of an instance.

Declaration
public virtual int Update(IDictionary values)
Parameters
Type Name Description
System.Collections.IDictionary values
Returns
Type Description
System.Int32

ValidateItem(TObject)

Asserts that the state of an item is valid.

Declaration
protected void ValidateItem(TObject item)
Parameters
Type Name Description
TObject item

The item to validate.

Events

Deleted

Occurs when an item was deleted

Declaration
public event DataSourceStatusEventHandler Deleted
Event Type
Type Description
DataSourceStatusEventHandler

Deleting

Occurs when an item is about to be deleted

Declaration
public event DataSourceMethodEventHandler Deleting
Event Type
Type Description
DataSourceMethodEventHandler

Inserted

Occurs when an item was inserted

Declaration
public event DataSourceStatusEventHandler Inserted
Event Type
Type Description
DataSourceStatusEventHandler

Inserting

Occurs when an item is about to be inserted

Declaration
public event DataSourceMethodEventHandler Inserting
Event Type
Type Description
DataSourceMethodEventHandler

Selected

Occurs when a select was executed

Declaration
public event DataSourceStatusEventHandler Selected
Event Type
Type Description
DataSourceStatusEventHandler

Selecting

Occurs when a select is about to be executed

Declaration
public event DataSourceMethodEventHandler Selecting
Event Type
Type Description
DataSourceMethodEventHandler

Updated

Occurs when an item was updated

Declaration
public event DataSourceStatusEventHandler Updated
Event Type
Type Description
DataSourceStatusEventHandler

Updating

Occurs when an item is about to be updated

Declaration
public event DataSourceMethodEventHandler Updating
Event Type
Type Description
DataSourceMethodEventHandler

Implements

Extension Methods