在Entity上执行命令

时间:2012-07-13 22:47:37

标签: mysql linq entity execute

protected void Button2_Click(object sender, EventArgs e)
{
    Response.Write(Execute("SELECT NOW()"));
}

public string Execute(string storedProcedureName)
{
    using (EntityConnection connection = (EntityConnection)new EGModel.EGEntity().Connection)
    {
        using (EntityCommand command = connection.CreateCommand())
        {
            command.CommandType = CommandType.Text;
            command.CommandText = storedProcedureName;
            connection.Open();
            return command.ExecuteScalar().ToString();
        }
    }
}

我收到错误“查询语法无效。靠近第1行,第13列。”;我很好奇,为什么这个错误? (Mysql实体连接)

1 个答案:

答案 0 :(得分:0)

    var A = new EGModel.EGEntity().Connection;

    var command = ((EntityConnection)(A)).StoreConnection.CreateCommand();
    command.CommandType = System.Data.CommandType.Text;
    command.CommandText = "SELECT NOW()";
    ((EntityConnection)(A)).StoreConnection.Open();
    string id = (string)command.ExecuteScalar();

@GTSouza感谢您的评论,