DbUpdateConcurrencyException - wrong SQL generated

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for MySQL
Post Reply
Adaś
Posts: 12
Joined: Sat 06 Apr 2019 20:09

DbUpdateConcurrencyException - wrong SQL generated

Post by Adaś » Mon 25 May 2020 16:54

Dont know why but this simple code:

Code: Select all

          
Guild guild = _context.Guilds.Where(w => w.GuildId == guildId).SingleOrDefault();
if (guild != null)
{
	GuildMemberRank guildMemberRank = (guild.GuildMembers.Count() == 0 ? GuildMemberRank.GuildMaster : GuildMemberRank.Member);

        guild.GuildMembers.Add(new GuildMember() { GuildRank = guildMemberRank, JoinDate = DateTime.Now, UserId = userId });
        _context.SaveChanges();
}
else
{
        throw new AppException("Guild not found!");
 }
generates DbUpdateConcurrencyException. Checked debug and noticed that instead of INSERT there is called update:

Code: Select all

Executed DbCommand (5ms) [Parameters=[p3='?' (DbType = Int32), p0='?' (DbType = Int32), p1='?' (DbType = Int32), p2='?' (DbType = DateTime)], CommandType='Text', CommandTimeout='30']
UPDATE GuildMembers SET GuildId = :p0, GuildRank = :p1, JoinDate = :p2 WHERE UserId = :p3;
Any idea how to fix it?

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: DbUpdateConcurrencyException - wrong SQL generated

Post by Shalex » Fri 05 Jun 2020 20:56

Please localize the issue in a small test project and send it with the corresponding DDL/DML script to us via contact form.

Post Reply