Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有人在Subsonic3、linq、MySQL和存储过程方面取得过成功吗_Mysql_Linq_Stored Procedures_Subsonic3 - Fatal编程技术网

有人在Subsonic3、linq、MySQL和存储过程方面取得过成功吗

有人在Subsonic3、linq、MySQL和存储过程方面取得过成功吗,mysql,linq,stored-procedures,subsonic3,Mysql,Linq,Stored Procedures,Subsonic3,我一直在尝试在Subsonic3中使用linq模板运行MySQL存储过程。我在MySQL.ttinclude文件中添加了一些函数,该文件似乎生成了存储过程引用类。但是,当我运行代码并调用存储过程时,似乎总是得到空结果: public DataSet SPTotalCallsByHour(int period) { rt.rtDB ee = new rt.rtDB(); StoredProcedure sp = ee.Totals_By_Hour(p

我一直在尝试在Subsonic3中使用linq模板运行MySQL存储过程。我在MySQL.ttinclude文件中添加了一些函数,该文件似乎生成了存储过程引用类。但是,当我运行代码并调用存储过程时,似乎总是得到空结果:

    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;
    }
有人使用MySQL存储过程处理Subsonic3吗?如果是的话,你能解释一下你是如何让他们工作的吗

您是否直接使用了亚音速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 GetSPParams(字符串spName){
var result=新列表();
MySqlCommand cmd=新的MySqlCommand();
使用(conn=newmysqlconnection(ConnectionString))
{
conn.Open();
cmd.Connection=conn;
cmd.CommandText=spName;
cmd.CommandType=CommandType.storedProcess;
尝试
{
MySqlCommandBuilder.DeriveParameters(cmd);
}
抓住
{
}
如果(cmd.Parameters.Count>0)
{
foreach(cmd.Parameters中的MySqlParameter参数)
{
SPParam p=新的SPParam();
p、 SysType=GetSysType(param.MySqlDbType.ToString());
p、 DbType=param.DbType.ToString();
p、 名称=param.ParameterName;
p、 CleanName=清除(p.Name);
结果:添加(p);
}
}
康涅狄格州关闭();
}
返回结果;
}

List GetSPs(){
var result=新列表();
字符串[]spNames=GetSPList();
foreach(spNames中的字符串spName){
var sp=新sp();
sp.Name=spName;
sp.CleanName=清理(sp.Name);
sp.Parameters=GetSPParams(sp.Name);
结果:添加(sp);
}
返回结果;

}

我从来没有为mysql和subsonic使用过存储过程,但我也没有这么努力过。我的理由是,您有比内联sql更好的东西

我想我是代表大众说的,存储过程被用来在应用程序中绕过数据库代码(sql负载),点在这里,点在那里 因此,程序员将使用存储过程来分离这两个问题,并使其更易于更新/更改/修复

现在,如果您使用亚音速或任何其他类型的DAL和实体,那么您不需要编写sql语句,只需编写代码。。。。亚音速,linq等知道该怎么做,并为你翻译

因此,您实际上不需要存储过程,如果您的数据库有问题,您只需再次运行TT文件


剩下的就是代码,你的程序。因此,也许这不是您想要的答案,但请不要使用存储过程,充分利用使用亚音速之类的东西的乐趣,我们将忘记所有关于数据库的内容,只考虑代码。

我在执行没有参数的SP和尝试读回输出时遇到问题。似乎你必须这样做


不确定此问题是否在3.0中继续存在。可以试试。

为什么有空的挡块?那几乎从来都不好。我只是太懒了。。我还没有完成这门课。。我通常会在以后添加我的异常处理。我完全同意。。我正在别人的数据库上建立一个数据层,他编写了一些庞大的存储过程,我没有时间在目标代码中重现。因此,对我来说,运行他现有的存储过程是最快的选择。
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;
SubSonic.StoredProcedure sp = SPs.UspNoParamProc();
//Stored Procedure command Is Null... ensure command is created
string dummy = sp.Command.CommandSql;

rptList.DataSource = sp.GetReader();
rptList.DataBind();