实体框架和MariaDB - phpMyAdmin

时间:2016-10-29 21:37:49

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

我试图在我的数据库中按照以下示例执行插入: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。

2 个答案:

答案 0 :(得分:0)

DEFAULT_VALUESROW_COUNT可以在SQL Server中找到,而不是MySQL,也不是MariaDB。您的实体框架配置需要更改。

答案 1 :(得分:0)

如果你调试sql语句

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

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