Castle. activerecord returns an object class using a stored procedure

Source: Internet
Author: User

 
This issue has been studied in the past few days.
I have not found a solution for searching the Internet. I only need to execute the stored procedure in the nhib.pdf.
One way to operate nhib.pdf in it
So I wrote the following class.

Of course, the test can only be passed, and there may be many problems to be solved one by one.

Namespace chalumna. castleext
{
Using Castle. activerecord;
Using Castle. activerecord. Framework;
Using Castle. activerecord. Framework. config;
Using system;

Using nhib.pdf;
Using nhib.pdf. cfg;
Using nhib.pdf. expression;
Using system. Collections. Generic;
Using system. text;
Using system. Data;
Public class Execute
{
/** // <Summary>
/// Use the stored procedure to fill the object class, ZOU Jian, 2008 1 24
/// </Summary>
/// <Typeparam name = "T"> entity class </typeparam>
/// <Param name = "spname"> name of the stored procedure </param>
/// <Param name = "IDICT"> parameter dictionary </param>
/// <Returns> one entity class ilist </returns>
Public static ilist <t> getlist <t> (string spname, idictionary <string, Object> IDICT ){
Type type = typeof (t );
// Chsword. dodatabase d = new chsword. dodatabase ();
Stringbuilder sp = new stringbuilder ();
Foreach (string key in IDICT. Keys ){
Sp. appendformat (": {0},", key );
}
If (sp. length! = 0)
Sp. Length --;
String map = string. Format (@ "<SQL-query name = '{0}'>
<Return class = '{1}'/>
Exec {0} {2}
</SQL-query> ",
Spname,
Type. Name,
Sp. tostring ()
);

Execute. createquerymapping (type, MAP); // create an SQL-Query
Isessionfactoryholder holder = activerecordmediator. getsessionfactoryholder ();

Isession session = holder. createsession (type );
IQUERY query = session. getnamedquery (spname );

Foreach (string key in IDICT. Keys ){
Query = query. setparameter (Key, IDICT [Key]);
}
Return query. List <t> ();
}
/** // <Summary>
/// Create an SQL-Query
/// </Summary>
/// <Param name = "type"> type, used as the key </param>
/// <Param name = "XML"> SQL-query node </param>
Public static void createquerymapping (type, string XML ){
Isessionfactoryholder holder = activerecordmediator. getsessionfactoryholder ();
Configuration Config = holder. getconfiguration (holder. getroottype (type ));

// Xml =;
Config. addxmlstring (
String. format ("Configuration. mappingschemaxmlns,
Type. Assembly. fullname,
Type. namespace, // namespace
XML // content is <SQL-query/>
)
);
// Return config. namedsqlqueries. Count. tostring ();
}
}
}

 

The usage is as follows:

Idictionary <string, Object> P = new dictionary <string, Object> (); // Parameter
P. Add ("userid", 10000); // parameter 1
P. Add ("ID", 17002); // parameter 2
P. Add ("groupid", 51); // parameter 3
Propertybag. Add ("list ",
Chalumna. castleext. Execute. getlist <logtoaccount> (// Execute
"Note_select", P
));
Propertybag. Add is a system dictionary in monorail. The test is normal.

However, the following are not enough (I think)

the parameter cannot be out.
you cannot associate a class with one. You can only create a new class based on fields in the stored procedure, or extend the original entity class.
I cannot think of it. If you are interested, try it on your own.

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.