在执行插入操作应用程序时,在asp.net核心应用程序上抛出错误。以前的应用程序是asp.net核心1.1最近我更新到asp.net core 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,Nullable1 commandType) in C:\projects\dapper\Dapper\SqlMapper.cs:line 443 at MySqlAdapter.Insert(IDbConnection connection, IDbTransaction transaction, Nullable
1 commandTimeout,String tableName,String columnList,String parameterList,IEnumerable1 keyProperties, Object entityToInsert) in C:\projects\dapper\Dapper.Contrib\SqlMapperExtensions.cs:line 897
1 commandTimeout)in C:\ projects \ dapper \ Dapper.Contrib \ SqlMapperExtensions.cs:第355行 在RecruiterinsiderPortal.Data.AgencyRegionRepository.Save(Int32 userId,List`1 regions)in C:\ Empite \ RI \ RecruiterinsiderPortal \ RecruiterinsiderPortal \库\ RecruiterinsiderPortal.Data \ AgencyRegionRepository.cs:线 67
at Dapper.Contrib.Extensions.SqlMapperExtensions.Insert[T](IDbConnection connection, T entityToInsert, IDbTransaction transaction, Nullable
mysql版本是5.7.19
问题是什么?
更新
这是区域模型
[Table("regions")]
public class AgencyRegion
{
[Key]
public int Id { get; set; }
public int UserId { get; set; }
public int RegionId { get; set; }
}
更新2
这是我发现的问题。我将在dapper存储库上打开问题,当我将dapper和contrib libs更新为最新版本1.50.4时插入,更新会抛出异常。因此我将Dapper降级为1.50.2并将其降至1.50.0然后工作正常。