Value Lists with ODataDB

Value Lists with ODataDB

ODataDB supports the following configurations:

ODataDB creates the required OData objects automatically.

The built-in JavaScript client and SaveToDB 8+ supports these features from the box.

Suppose a database has the following tables:

Database Diagram of Sample 02 - Advanced Features

The s02.cashbook entity type will have the following declaration:

<EntityType Name="cashbook">
    <Key>
        <PropertyRef Name="id"/>
    </Key>
    <Property Name="id" Type="Edm.Int32" Nullable="false">
        <Annotation Term="Core.Permission" EnumMember="Core.Permission/Read"/>
    </Property>
    <Property Name="date" Type="Edm.Date" Nullable="false"/>
    <Property Name="account_id" Type="Edm.Int32" Nullable="false"/>
    <Property Name="item_id" Type="Edm.Int32"/>
    <Property Name="company_id" Type="Edm.Int32"/>
    <Property Name="debit" Type="Edm.Decimal"/>
    <Property Name="credit" Type="Edm.Decimal"/>
    <NavigationProperty Name="account" Type="s02.accounts" Partner="cashbooks">
        <ReferentialConstraint Property="account_id" ReferencedProperty="id"/>
    </NavigationProperty>
    <NavigationProperty Name="company" Type="s02.companies" Partner="cashbooks">
        <ReferentialConstraint Property="company_id" ReferencedProperty="id"/>
    </NavigationProperty>
    <NavigationProperty Name="item" Type="s02.items" Partner="cashbooks">
        <ReferentialConstraint Property="item_id" ReferencedProperty="id"/>
    </NavigationProperty>
</EntityType>

The client applications can use NavigationProperties to create lists.

Suppose the xls.handlers table contains the following configuration:

IDTABLE_SCHEMATABLE_NAMECOLUMN_NAMEEVENT_NAMEHANDLER_SCHEMAHANDLER_NAMEHANDLER_TYPEHANDLER_CODE
 s02cashbookaccount_idValidationLists02accountsTABLEid, +name
 s02cashbookitem_idValidationLists02itemsTABLEid, +name
 s02cashbookcompany_idValidationLists02companiesTABLEid, +name

The s02.cashbook entity type will have the following declaration for the account_id, item_id, and company_id columns:

<EntityType Name="cashbook">
    ...
    <Property Name="account_id" Type="Edm.Int32" Nullable="false">
        <Annotation Term="ODataDB.ValueList" Path="default.default/s02_accounts_select_id_name_order_by_name1"/>
    </Property>
    <Property Name="item_id" Type="Edm.Int32">
        <Annotation Term="ODataDB.ValueList" Path="default.default/s02_items_select_id_name_order_by_name1"/>
    </Property>
    <Property Name="company_id" Type="Edm.Int32">
        <Annotation Term="ODataDB.ValueList" Path="default.default/s02_companies_select_id_name_order_by_name1"/>
    </Property>
    ...
</EntityType>

The ODataDB.ValueList annotations contain paths to the declared FunctionImports in the default EntityContainer:

<FunctionImport Name="s02_accounts_select_id_name_order_by_name1" Function="s02.accounts_select_id_name_order_by_name1" EntitySet="s02_accounts"/>
<FunctionImport Name="s02_items_select_id_name_order_by_name1" Function="s02.items_select_id_name_order_by_name1" EntitySet="s02_items"/>
<FunctionImport Name="s02_companies_select_id_name_order_by_name1" Function="s02.companies_select_id_name_order_by_name1" EntitySet="s02_companies"/>

Here are the declared functions in the s02 schema:

<Function Name="accounts_select_id_name_order_by_name1">
    <ReturnType Type="Collection(s02.accounts)"/>
</Function>
<Function Name="items_select_id_name_order_by_name1">
    <ReturnType Type="Collection(s02.items)"/>
</Function>
<Function Name="companies_select_id_name_order_by_name1">
    <ReturnType Type="Collection(s02.companies)"/>
</Function>

Here is a sample configuration for the s02.usp_cashbook procedure that selects data from the s02.cashbook table and has three parameters: account_id, item_id, and company_id:

IDTABLE_SCHEMATABLE_NAMECOLUMN_NAMEEVENT_NAMEHANDLER_SCHEMAHANDLER_NAMEHANDLER_TYPEHANDLER_CODE
 s02usp_cashbookaccount_idParameterValuess02accountsTABLEid, +name
 s02usp_cashbookitem_idParameterValuess02itemsTABLEid, +name
 s02usp_cashbookcompany_idParameterValuess02companiesTABLEid, +name

Here is a function declaration:

<EntityType Name="usp_cashbook_result" BaseType="s02.cashbook" OpenType="true"/>
<Function Name="usp_cashbook">
    <Parameter Name="account_id" Type="Edm.Int32">
        <Annotation Term="ODataDB.ValueList" Path="default.default/s02_accounts_select_id_name_order_by_name"/>
    </Parameter>
    <Parameter Name="item_id" Type="Edm.Int32">
        <Annotation Term="ODataDB.ValueList" Path="default.default/s02_items_select_id_name_order_by_name"/>
    </Parameter>
    <Parameter Name="company_id" Type="Edm.Int32">
        <Annotation Term="ODataDB.ValueList" Path="default.default/s02_companies_select_id_name_order_by_name"/>
    </Parameter>
    <ReturnType Type="Collection(s02.usp_cashbook_result)"/>
</Function>

It also uses the ODataDB.ValueList annotation to link functions to get parameter values.

You can learn the complete model online:

https://odatadb.savetodb.com/v4/mssql-023/default/en-us/$metadata