LinqConnect Documentation
In This Topic
    Method Mapping
    In This Topic
    Method Mapping
    LinqConnect Documentation
    Method Mapping
    [email protected]

    LinqConnect fully supports mapping methods to stored procedures and functions. For example we will map the following methods:


    C#csharpCopy Code
    public class MyDataContext : DataContext {
     
        // ...
     
        public Double? GetPrice(string product) {
            //...
        }
     
        public ISingleResult<Company> GetCompany(string companyName) {
            //...
        }
     
        public IMultipleResults GetMultipleResultSets() {
            //...
        }
    }
    Visual BasicCopy Code
    Public Class MyDataContext
        Inherits DataContext
    
        ' ...
    
        Public Function GetPrice(product As String) As Nullable(Of Double)
            '...
        End Function
    
        Public Function GetCompany(companyName As String) As ISingleResult(Of Company)
            '...
        End Function
    
        Public Function GetMultipleResultSets() As IMultipleResults
            '...
        End Function
    
    End Class
    

    to the stored function GetPrice(PRODUCT IN VARCHAR2) and stored procedures GetCompany(CompanyName IN VARCHAR2) and GetMultipleResultSets(). GetPrice method returns a scalar value, while GetCompany method returns a collection of Company entities, and GetMultipleResultSets returns three collections: two collections of Company and Order entities, and a collection of AddressType coplex types.

    Attribute Mapping

    Function, Parameter, and ResultType attributes are used for attribute mapping of methods. See the following tables for their properties' descriptions.

    Function Attribute Properties

    Property Type Description
    IsComposable Boolean Specifies whether a method is mapped to a function (true) or to a stored procedure (false).
    Name String Specifies the name of the function or stored procedure.

    Parameter Attribute Properties

    Property Type Description
    DbType String Specifies the type of the parameter.
    Name String Specifies the name of the parameter.

    ResultType Attribute Properties

    Property Type Description
    Type System.Type Specifies the valid or expected type mapping for a function having various result types.
    Order System.Int32 Specifies the ordinal number of returned from function resultset.

    See the example of the attribute mapping below:


    C#csharpCopy Code
    public class MyDataContext : DataContext {
     
        // ...
     
        [Function(Name="GetPrice", IsComposable=true)]
        public Double? GetPrice([Parameter(Name="PRODUCT", DbType="VARCHAR2")] string product) {
            //...
        }
     
        [Function(Name="GetCompany")]
        public ISingleResult<Company> GetCompany([Parameter(Name="CompanyName", DbType="VARCHAR2")] string companyName) {
            //...
        }
     
        [Function(Name="GetMultipleResultSets")]
        [ResultType(typeof(Company), 1)]
        [ResultType(typeof(Order), 2)]
        [ResultType(typeof(AddressType), 3)]
        public IMultipleResults GetMultipleResultSets() {
            //...
        }
     
    }
    Visual BasicCopy Code
    Public Class MyDataContext
        Inherits DataContext
    
        ' ...
    
        <[Function](Name:="GetPrice", IsComposable:=True)>
        Public Function GetPrice(<Parameter(Name:="PRODUCT", DbType:="VARCHAR2")> product As String) As Nullable(Of Double)
            '...
        End Function
    
        <[Function](Name:="GetCompany")>
        Public Function GetCompany(<Parameter(Name:="CompanyName", DbType:="VARCHAR2")> companyName As String) As ISingleResult(Of Company)
            '...
        End Function
    
        <[Function](Name:="GetMultipleResultSets")> _
        <ResultType(GetType(Company), 1)> _
        <ResultType(GetType(Order), 2)> _
        <ResultType(GetType(AddressType), 3)> _
        Public Function GetMultipleResultSets() As IMultipleResults
            '...
        End Function
    
    End Class
    

    XML Mapping

    XML mapping of methods uses Function, Parameter, and ElementType tags.

    <Function Name="GetPrice" Method="GetPrice" IsComposable="true" >
      <Parameter Name="PRODUCT" Member="product" DbType="VARCHAR2" />
    </Function>
    <Function Name="GetCompany" Method="GetCompany">
      <Parameter Name="CompanyName" Member="companyName" DbType="VARCHAR2" />
      <ElementType Name="Company" />
    </Function>
    <Function Name="GetMultipleResultSets" Method="GetMultipleResultSets">
      <ElementType Name="Company" />
      <ElementType Name="Order" />
      <ElementType Type="AddressType" />
    </Function>

    Fluent Mapping

    Fluent Mapping of methods is not supported.