Dapper或MySql找不到包含句号“."的存储过程. [英] Dapper or MySql not finding stored procedures that contain a full stop "."

查看:165
本文介绍了Dapper或MySql找不到包含句号“."的存储过程.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的c#控制台,该控制台使用Dapper ORM调用本地MySql数据库,以执行名为users.UserCreate的存储过程.

I've got a simple c# console that uses the Dapper ORM to make a call to a local MySql database in order to execute a stored procedure called users.UserCreate.

但是,在运行查询时,出现异常提示

However, when running the query I get an exception saying

在数据库用户"中找不到过程或函数"UserCreate"

Procedure or function 'UserCreate' cannot be found in database 'users'

但是users不是数据库local_db是.

这里是一个示例用法:

public virtual Task CreateAsync(User user)
{
        using (var con = new MySqlConnection(_dbConn))
            return con.ExecuteAsync("users.UserCreate", user, commandType: CommandType.StoredProcedure);
}

_dbConn包含连接字符串,还将数据库的名称表示为local_db.

_dbConn contains the connection string, also stating the name of the database as local_db.

这是存储过程的样子:

DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `users.UserCreate`(IN `@UserId` VARCHAR(128), IN `@UserName` VARCHAR(255), IN `@PasswordHash` LONGTEXT, IN `@SecurityStamp` LONGTEXT)
    NO SQL
INSERT INTO Users
(Id, UserName, PasswordHash, SecurityStamp, EmailConfirmed, PhoneNumberConfirmed, TwoFactorEnabled, LockoutEnabled, DateCreated, DateUpdated, IsDeleted)
VALUES
(@UserId, @UserName, @PasswordHash, @SecurityStamp, 0, 0, 0, 0, CURRENT_DATE, CURRENT_DATE, 0)$$
DELIMITER ;

问题与MySql或Dapper有关吗?我对SQL Server中的存储过程使用了类似的命名约定,也使用了Dapper,并且以前没有这个问题.

Is the problem something to do with MySql or Dapper? I use a similar naming convention for stored procedures in SQL Server, also using Dapper, and haven't had this problem before.

我尝试过:

  • 使用"local_db.users.UserCreate"
  • 使用"local_db.UserCreate"
  • 使用"UserCreate"

有什么想法吗?

推荐答案

好吧,事实证明,从使用SQL到MySQL的转换在MySQL的(in)功能方面充满了学习曲线.为了避开使用句号/句点(.")的架构命名约定,我只是将其替换为下划线.

Well, turns out conversion from using SQL to MySQL has been full of learning curves in terms of MySQL's (in)capabilities. To get around the schema naming conventions using full-stops/periods (".") I've just replaced it with an underscore instead.

对于任何面临同样困境的人,使用下划线,从长远来看,您将节省数小时的头痛!

For anyone else facing the same dilemma, use underscores, you'll save yourself hours of headaches in the long run!

这篇关于Dapper或MySql找不到包含句号“."的存储过程.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆