AdvantageCMS.Core.Common.BaseClasses Namespace
Build With Advantage

IDataAccessable Interface

Contract implemented by business entities to enable the data access layer to execute stored procedures on their behalf. The entity is responsible for supplying parameters, receiving result sets, and optionally providing raw SQL — while the data access layer owns connection lifecycle, command execution, and transaction management.

Namespace:  AdvantageCMS.Data.Interfaces
Assembly:  AdvantageCMS.Data (in AdvantageCMS.Data.dll)

Syntax


public interface IDataAccessable

Remarks


Each method receives a commandName that identifies which stored procedure (or logical operation) is being executed. Implementations use this to branch behavior — returning different parameter arrays and mapping different result set columns depending on the operation.

Typical flow:

  1. The data access layer calls GetParameters(String) to get the parameter values for the stored procedure.
  2. It executes the stored procedure using those parameters.
  3. It passes the result sets back to SetData(String, IListSource) so the entity can populate its properties from the returned data.

Examples


The following example shows a CustomerData entity that supports insert/update and retrieval operations via two stored procedures.

C#
[Serializable]
internal class CustomerData : IDataAccessable
{I'
    // -- Properties populated from or sent to the database --
    public Guid   CustomerID   { get; set; }
    public string CompanyName  { get; set; }
    public string ContactEmail { get; set; }
    public int    AccountTier  { get; set; }
    public bool   IsActive     { get; set; }

    // -- Result metadata set by SetData --
    internal bool   Success { get; set; }
    internal string Message { get; set; }

    /// <summary>
    /// Returns the ordered parameter array for the given stored procedure.
    /// Array position must match the stored procedure's parameter order exactly.
    /// </summary>
    public object[] GetParameters(string commandName)
    {
        switch (commandName)
        {
            // Maps to: @CustomerID, @CompanyName, @ContactEmail, @AccountTier, @IsActive
            case "Customer_InsertUpdate":
                return new object[]
                {
                    CustomerID,
                    CompanyName,
                    ContactEmail,
                    AccountTier,
                    IsActive
                };

            // Maps to: @CustomerID
            case "Customer_GetByID":
                return new object[]
                {
                    CustomerID
                };

            default:
                return new object[] { };
        }
    }

    /// <summary>
    /// Returns raw SQL for the command. Return empty string when using stored procedures.
    /// </summary>
    public string GetSQL(string commandName)
    {
        return string.Empty;
    }

    /// <summary>
    /// Populates entity properties from the stored procedure's result set.
    /// Each row in the result set is an IDictionary keyed by column name.
    /// </summary>
    public void SetData(string commandName, IListSource resultSets)
    {
        IList results = resultSets.GetList();
        if (results == null || results.Count == 0)
            return;

        IDictionary row = (IDictionary)results[0];

        switch (commandName)
        {
            case "Customer_InsertUpdate":
                Success = row["Status"].ToString() == "1";
                Message = row["Message"].ToString();
                break;

            case "Customer_GetByID":
                CustomerID   = (Guid)row["CustomerID"];
                CompanyName  = row["CompanyName"].ToString();
                ContactEmail = row["ContactEmail"].ToString();
                AccountTier  = (int)row["AccountTier"];
                IsActive     = (bool)row["IsActive"];
                break;
        }
    }
}