首页 > 数据库技术 > 详细

LightSpeed 之Sql和存储过程的使用

时间:2015-07-31 14:29:54      阅读:207      评论:0      收藏:0      [点我收藏+]

虽然使用LightSpeed提供的Query就可以解决绝大部分问题,但如果业务逻辑过于复杂,有时候还是需要执行SQL语句或者存储过程

用SQL的方式就是使用FindBySql。

FindBySql的参数只有一个  Command。

而创建Command的方式则不是那么简单

var cmd = unitOfWork.Context.DataProviderObjectFactory.CreateCommand();

Command需要赋予Text,也许还会有参数

cmd.CommandText = "exec dbo.my_stored_proc";
//或
cmd.CommandText = "SELECT * FROM Table";
var metadata = new[] { new SqlMetaData("value", SqlDbType.NVarChar, 10) };  // the members of your SQL Server table type

var data1 = new SqlDataRecord(metadata);  // In reality you‘d create a helper method for this
data1.SetValues("1");
var data2 = new SqlDataRecord(metadata);
data2.SetValues("2");
var data = new [] { data1, data2 };

cmd.Parameters.Add(new SqlParameter("@stringArrayInput", data) { SqlDbType = SqlDbType.Structured });

 

LightSpeed 之Sql和存储过程的使用

原文:http://www.cnblogs.com/TiestoRay/p/4691816.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!