自定义SQL和存储过程查询

Top  Previous  Next

QueryColumnsGenerator.exe工具会为所有的存储过程生成调用包装类,可以像使用一个.NET的方法一样调用存储过程。

 

例如,如果指定QueryColumnsGenerator.exe工具的Root Class Name为Northwind为Northwind数据库生成了所有的存储过程调用包装方法代码,则可以像下面这样调用存储过程:

 

int ret = -1;

DataSet ds = Northwind.SalesbyYear(db, out ret, new DateTime(1800, 9, 9), DateTime.Now);

 

string outStr = "1";

ds = Northwind.SalesByCategoryTest(db, out ret, "test1", "1997", ref outStr);

 

 

除此之外,还可以使用Datebase.CustomSql()方法和Database.StoredProcedure()方法,以自定义的方式调用自定义SQL或存储过程。