Datarabbit lightweight data access framework (06) -- irelationaccesser

Source: Internet
Author: User
(Fully qualified class name: Datarabbit. relation. irelationaccesser )

The iormaccesser described earlier is Single Table And itableaccesser is Single Table For link-based access, if we want to perform a cross-Table search such as joint query, they will not be able to achieve the goal. In this case, you can use irelationaccesser. Unlike iormaccesser and itableaccesser, irelationaccesser is targeted at a specific table in the database. In datarabbit, irelationaccesser is recommended for all cross-Table operations (unless there is a better solution in the future ).

Irelationaccesser divides data access into two types: Query and command. The query returns the dataset, and the command does not return the value. In addition, irelationaccesser supports executing query statements with parameters.
We can obtain the irelationaccesser reference from the idataaccesser entry point of datarabbit: 

IrelationaccesserRelationaccesser = Dataaccesser. getrelationaccesser ( Null );


The complete definition of the irelationaccesser interface is as follows, which only contains three methods: Public   Interface  Irelationaccesser: Itransactionaccesser
{
///   <Summary>
/// Docommand
///   </Summary>
Void Docommand ( String Command );

//<Summary>
///Doquery query data
/// </Summary>
DatasetDoquery (StringQuery );

///   <Summary>
/// Excuteregularquery executes a query statement with parameters. The parameter value is provided by paravalues.
///   </Summary>
/// <Param name = "regularquery"> query statement with parameters </param>
/// <Param name = "paraprefix"> prefix of a parameter in a query statement, which can be customized. </param>
/// <Param name = "paravalues"> the key is the parameter name without the parameter prefix. </param>
DatasetExcuteregularquery ( String Regularquery, String Paraprefix, idictionary < String , Object > Paravalues );
}

Suppose we want to perform a joint query, we can do this:StringJoinselect= "Select errordetail. *, taskerror. LocationFromErrordetail inner join taskerror on errordetail. errorid = taskerror. ID where (taskerror. ID = '1 ')";
DatasetDS=Relationaccesser.Doquery(Joinselect );

If you want to use parameterized queries, you can call the excuteregularquery method. Now we can call the excuteregularquery method to implement the above functions: String Joinselect =   " Select errordetail. *, taskerror. Location from errordetail inner join taskerror on errordetail. errorid = taskerror. ID where (taskerror. ID = @ ID) " ;
// Prepare Parameters
Idictionary < String , Object > Dic =   New  Dictionary < String , Object > ();
Dic. Add ( " ID " , 1 );//Parameter names do not require a parameter prefix
// Query
Dataset DS2 = Relationaccesser . Excuteregularquery (joinselect, " @ " , DIC );

Note that the paraprefix parameter in the excuteregularquery method is used to indicate the prefix of the parameter used in the query statement. You can specify this prefix by yourself, datarabbit automatically converts it to the parameter prefix required by the database before execution. For example, if the background database is Oracle, the parameter prefix "@" of the preceding statement will be automatically converted to the prefix ":" required by Oracle.

Go to: datarabbit lightweight data access framework-Sequence

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.