有没有人在 Subsonic3、linq、MySQL 和存储过程方面取得过成功
我一直在尝试让 MySQL 存储过程与 Subsonic3 中的 linq 模板一起运行。我向 MySQL.ttinclude 文件添加了一些函数,这些函数似乎已生成存储过程引用类。然而,当我运行代码并调用存储过程时,我似乎总是得到 NULL 结果:
public DataSet SPTotalCallsByHour(int period)
{
rt.rtDB ee = new rt.rtDB();
StoredProcedure sp = ee.Totals_By_Hour(period.ToString());
sp.Execute();
return (DataSet)sp.Output;
}
有谁得到了与 Subsonic3 一起使用的 MySQL 存储过程吗?如果是这样,您能解释一下您是如何让它们工作的吗?
您是否直接使用了 subsonic 3 版本中的 ttinclude 文件?
这些是我添加到 MySQL.ttinclude 文件中的两个函数:
List<SPParam> GetSPParams(string spName){
var result=new List<SPParam>();
MySqlCommand cmd = new MySqlCommand();
using(conn=new MySqlConnection(ConnectionString))
{
conn.Open();
cmd.Connection = conn;
cmd.CommandText = spName;
cmd.CommandType = CommandType.StoredProcedure;
try
{
MySqlCommandBuilder.DeriveParameters(cmd);
}
catch
{
}
if(cmd.Parameters.Count > 0)
{
foreach(MySqlParameter param in cmd.Parameters)
{
SPParam p = new SPParam();
p.SysType = GetSysType(param.MySqlDbType.ToString());
p.DbType = param.DbType.ToString();
p.Name = param.ParameterName;
p.CleanName=CleanUp(p.Name);
result.Add(p);
}
}
conn.Close();
}
return result;
}
List<SP> GetSPs(){
var result=new List<SP>();
string[] spNames = GetSPList();
foreach(string spName in spNames){
var sp=new SP();
sp.Name=spName;
sp.CleanName=CleanUp(sp.Name);
sp.Parameters=GetSPParams(sp.Name);
result.Add(sp);
}
return result;
}
I have been trying to get MySQL stored procedures running with the linq templates in Subsonic3. I added some functions to the MySQL.ttinclude file that seems to have generated the stored procedure reference classes. However when I run the code and call the stored procedures I seem to always get NULL results:
public DataSet SPTotalCallsByHour(int period)
{
rt.rtDB ee = new rt.rtDB();
StoredProcedure sp = ee.Totals_By_Hour(period.ToString());
sp.Execute();
return (DataSet)sp.Output;
}
Has anyone got MySQL stored procedures working with Subsonic3? If so can you please explain how you got them to work?
Did you use the ttinclude files straight out of the subsonic 3 release?
These are the two functions I added to the MySQL.ttinclude file:
List<SPParam> GetSPParams(string spName){
var result=new List<SPParam>();
MySqlCommand cmd = new MySqlCommand();
using(conn=new MySqlConnection(ConnectionString))
{
conn.Open();
cmd.Connection = conn;
cmd.CommandText = spName;
cmd.CommandType = CommandType.StoredProcedure;
try
{
MySqlCommandBuilder.DeriveParameters(cmd);
}
catch
{
}
if(cmd.Parameters.Count > 0)
{
foreach(MySqlParameter param in cmd.Parameters)
{
SPParam p = new SPParam();
p.SysType = GetSysType(param.MySqlDbType.ToString());
p.DbType = param.DbType.ToString();
p.Name = param.ParameterName;
p.CleanName=CleanUp(p.Name);
result.Add(p);
}
}
conn.Close();
}
return result;
}
List<SP> GetSPs(){
var result=new List<SP>();
string[] spNames = GetSPList();
foreach(string spName in spNames){
var sp=new SP();
sp.Name=spName;
sp.CleanName=CleanUp(sp.Name);
sp.Parameters=GetSPParams(sp.Name);
result.Add(sp);
}
return result;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我从来没有让存储过程适用于 mysql 和 subsonic,但我也没有这么努力。我的理由是你有比内联sql更好的东西。
我想我代表大众说,存储过程用于绕过应用程序内的数据库代码(大量 SQL),这里点缀着那里
因此程序员将使用存储过程来分离这两个问题,并使其更容易更新/更改/修复。
现在,如果您使用 subsonic 或任何其他类型的 DAL 和实体,那么您无需编写 sql 语句,您只需编写代码...... subsonic、linq 等知道如何处理它并为您翻译它。
所以你并不真正需要存储过程,如果你的数据库有问题,你只需再次运行你的 TT 文件即可。
剩下的就是代码,你的程序。所以也许这不是您想要的答案,但是放弃存储过程并充分利用使用亚音速之类的东西是多么有趣,并且忘记所有数据库而只考虑代码。
i have never got stored procedures to work for mysql and subsonic, but i havent tried so hard either. my reasoning behind that you have something better than inline sql.
i think i speak for the masses that stored procedures was used to get around having database code (loads of sql) inside the application, dotted here n there
so programmers would use stored procedures to seperate the 2 concerns and make it easier to update/change/repair.
now if you use subsonic or any other kind of DAL and entities then you have no need to write sql statements as such, you just write code.... subsonic, linq etc know what to do with that and translate it for you.
so you dont really need stored procedures, if your database has a problem, you just run your TT files again.
the rest is code, your program. so maybe it is not the answer you would like, but sack the stored procedures and make use of how much fun it is to use something like subsonic and well forget all about your database and just think about the code.
我在执行不带参数的 SP 并尝试读回输出时遇到问题。看来你必须做这个解决办法;
不确定这个问题在3.0中是否仍然存在。或许可以尝试一下。
I had a problem executing a SP with no parameter and trying to read back ouput. Seems you have to do this work around;
Not sure if this problem continues to exist in 3.0 or not. Might try it out.