Dapper.Contrib插入异常(Dapper.Contrib Insert Exception

2019-10-30 04:24发布

在asp.net核心应用程序,当我执行INSERT操作应用抛出错误。 以前申请asp.net 1.1核心最近我更新到asp.net 2.0核心

using (var con = _connectionFactory.CreateConnection())
{
    con.Open();
    using (var transaction = con.BeginTransaction())
    {
        try
        {
            if (regions.Any())
            {

                con.Insert(regions.Select(c =>
                {
                    c.UserId = userId;
                    return c;
                }), transaction);
            }
            transaction.Commit();
        }
        catch(Exception exception)
        {
            transaction.Rollback();
        }
    }
}

例外的是

MySql.Data.MySqlClient.MySqlException(0X80004005):你在你的SQL语法错误; 检查对应于你的MySQL服务器版本使用附近的“正确的语法手册1s () values ()' at line 1 at MySql.Data.MySqlClient.MySqlStream.ReadPacket() at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId) at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force) at MySql.Data.MySqlClient.MySqlDataReader.NextResult() at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery() at Dapper.SqlMapper.ExecuteImpl(IDbConnection cnn, CommandDefinition& command) in C:\projects\dapper\Dapper\SqlMapper.cs:line 552 at Dapper.SqlMapper.Execute(IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Nullable 1的CommandTimeout,可空1 commandType) in C:\projects\dapper\Dapper\SqlMapper.cs:line 443 at MySqlAdapter.Insert(IDbConnection connection, IDbTransaction transaction, Nullable 1的CommandTimeout,字符串表名,弦乐科拉姆 NLIST,字符串PARAMETERLIST,IEnumerable的1 keyProperties, Object entityToInsert) in C:\projects\dapper\Dapper.Contrib\SqlMapperExtensions.cs:line 897
at Dapper.Contrib.Extensions.SqlMapperExtensions.Insert[T](IDbConnection connection, T entityToInsert, IDbTransaction transaction, Nullable
1 keyProperties, Object entityToInsert) in C:\projects\dapper\Dapper.Contrib\SqlMapperExtensions.cs:line 897
at Dapper.Contrib.Extensions.SqlMapperExtensions.Insert[T](IDbConnection connection, T entityToInsert, IDbTransaction transaction, Nullable
1 keyProperties, Object entityToInsert) in C:\projects\dapper\Dapper.Contrib\SqlMapperExtensions.cs:line 897
at Dapper.Contrib.Extensions.SqlMapperExtensions.Insert[T](IDbConnection connection, T entityToInsert, IDbTransaction transaction, Nullable
1的CommandTimeout)在C:\项目\ hardy中\ Dapper.Contrib \ SqlMapperExtensions.cs:线355
在RecruiterinsiderPortal.Data.AgencyRegionRepository.Save(的Int32用户id,List`1区)在C:\ Empite \ RI \ RecruiterinsiderPortal \ RecruiterinsiderPortal \库\ RecruiterinsiderPortal.Data \ AgencyRegionRepository.cs:67行

MySQL的版本是19年7月5日

究竟是什么问题?

UPDATE

这里是区模型

 [Table("regions")]
    public class AgencyRegion
    {
        [Key]
        public int  Id { get; set; }
        public int UserId { get; set; }
        public int RegionId { get; set; }
    }

更新2

这里是我发现这个问题。 我; M要开放问题上,当我到是1.50.4最新的插入,更新抛出异常更新和短小精悍的contrib库短小精悍库。 所以我降级到短小精悍到1.50.2及的Contrib中1.50.0然后工作正常。

文章来源: Dapper.Contrib Insert Exception