Duplicate Entry error in EFCore and Mysql

1

i am trying to import tab delimitted feed to mysql using EFCore 2.0 and Pomelo libraries.

Feed is as below....

"BusinessCombinationRecognizedIdentifiableAssetsAcquiredAndLiabilitiesAssumedAssets"    "us-gaap/2016"
"BusinessCombinationRecognizedIdentifiableAssetsAcquiredAndLiabilitiesAssumedCashAndEquivalents" "us-gaap/2016"

the code is as below

//Entity Class
[Table("tags")]
public partial class tag:BaseEntity
{
    [Key]
    [Column("tag", Order = 0)]
    [StringLength(256)]
    [FeedOrder(0)]
    public string tag1 { get; set; }

    [Key]
    [Column(Order = 1)]
    [StringLength(20)]
    [FeedOrder(1)]
    public string version { get; set; }

}


//Context
public class VDContext:DbContext
{

    public virtual DbSet<tag> tags { get; set; }
    public VDContext(DbContextOptions options):base(options){ }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<tag>()
            .Property(e => e.tag1)
            .IsUnicode(false);

        modelBuilder.Entity<tag>()
            .Property(e => e.version)
            .IsUnicode(false);
    }
}

I am getting the exception as below...

**MySql.Data.MySqlClient.MySqlException (0x80004005): Duplicate entry 'BusinessCombinationRecognizedIdentifiableAssetsAcquiredAndLiabil' for key 'PRIMARY' ---> MySql.Data.MySqlClient.MySqlException (0x80004005): Duplicate entry 'BusinessCombinationRecognizedIdentifiableAssetsAcquiredAndLiabil' for key 'PRIMARY'**


at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
   at MySqlConnector.Core.ResultSet.<ReadResultSetHeaderAsync>d__1.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\Core\ResultSet.cs:line 43
   at MySql.Data.MySqlClient.MySqlDataReader.ActivateResultSet(ResultSet resultSet) in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlDataReader.cs:line 92
   at MySql.Data.MySqlClient.MySqlDataReader.<ReadFirstResultSetAsync>d__65.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlDataReader.cs:line 297
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MySql.Data.MySqlClient.MySqlDataReader.<CreateAsync>d__64.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlDataReader.cs:line 287
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MySqlConnector.Core.TextCommandExecutor.<ExecuteReaderAsync>d__3.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\Core\TextCommandExecutor.cs:line 70
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteDbDataReader(CommandBehavior behavior) in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlCommand.cs:line 172
   at Microsoft.EntityFrameworkCore.Storage.Internal.MySqlRelationalCommand.<ExecuteAsync>d__3.MoveNext()
fail: Microsoft.EntityFrameworkCore.Update[10000]
      An exception occurred in the database while saving changes for context type 'vd.database.VDContext'.
      Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> MySql.Data.MySqlClient.MySqlException: Duplicate entry 'BusinessCombinationRecognizedIdentifiableAssetsAcquiredAndLiabil' for key 'PRIMARY' ---> MySql.Data.MySqlClient.MySqlException: Duplicate entry 'BusinessCombinationRecognizedIdentifiableAssetsAcquiredAndLiabil' for key 'PRIMARY'

I configured the tag length as 256 everywhere like entity, table..etc but it is taking only 64 characters length ("BusinessCombinationRecognizedIdentifiableAssetsAcquiredAndLiabil") and causing the Duplicate Entry Exception.

please help me how to solve this? and let me know if more details required..

c#
mysql
ef-core-2.0
ef-fluent-api
pomelo-entityframeworkcore-mysql
asked on Stack Overflow Feb 11, 2018 by SRIKANTH DASARI • edited Sep 23, 2020 by lauxjpn

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0