【问题标题】:Entity Framework and MariaDB - phpMyAdmin实体框架和 MariaDB - phpMyAdmin
【发布时间】:2016-10-29 21:37:49
【问题描述】:

我正在尝试按照以下示例在我的数据库中插入:http://insidemysql.com/howto-starting-with-mysql-ef-core-provider-and-connectornet-7-0-4/。我成功创建了数据库和表,但是由于某种原因,我在下面的 INSERT 上不断收到相同的错误:

var entry = new Sistema();

        using (var context = SistemaFactory.Create(connectionString))
        {
            context.Sistemas.Add(entry);
            context.SaveChanges();
        }

这是我的模型:

public class Sistema
{
    public int Id { get; set; }

    public List<Agenda> Agendas { get; set; }
}

还有我不断收到的错误:

{Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> MySql.Data.MySqlClient.MySqlException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'DEFAULT VALUES;
SELECT `Id`
FROM `Sistemas`
WHERE ROW_COUNT() = 1
 AND `Id`=' at line 2

到目前为止,我无法修复此错误,因此我使用的是 PostgreSQL 而不是 MySQL。

【问题讨论】:

  • 向我们展示产生错误的 SQL。
  • @RickJames 我不知道它是否可能,我能得到的唯一 SQL 已经在问题上了。
  • 我们需要看到“第 1 行”。 (有时第 3 方软件会妨碍您!)
  • @RickJames Visual Studio 只显示这个查询:DEFAULT VALUES;选择 Id FROM Sistemas WHERE ROW_COUNT() = 1 AND Id=
  • @RickJames 当我在 phpMyAdmin 上尝试此查询时,它会在“DEFAULT VALUES”行返回错误。

标签: c# mysql entity-framework asp.net-core mariadb


【解决方案1】:

DEFAULT_VALUESROW_COUNT 在 SQL Server 中找到,而不是在 MySQL 或 MariaDB 中。您的 Entity Framework 配置需要更改。

【讨论】:

    【解决方案2】:

    如果你调试sql语句

    context.Database.Log = statememnt => Console.WriteLine(statement);
    

    或类似的,您可能会注意到您尝试更新选择语句而不是表。 这是因为您的表没有主键。 定义一个,您将能够更新。

    【讨论】:

      猜你喜欢
      • 2013-02-10
      • 2011-10-11
      • 2020-08-12
      • 2011-08-20
      • 2011-10-25
      • 2013-04-13
      • 2016-07-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多