(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