我正在尝试使用 EFCore 2.0 和 Pomelo 库将制表符分隔的提要导入 mysql。
饲料如下......
"BusinessCombinationRecognizedIdentifiableAssetsAcquiredAndLiabilitiesAssumedAssets" "us-gaap/2016"
"BusinessCombinationRecognizedIdentifiableAssetsAcquiredAndLiabilitiesAssumedCashAndEquivalents" "us-gaap/2016"
代码如下
//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);
}
}
我收到如下异常...
**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'
我将标签长度配置为 256,例如实体、表格等,但它只占用 64 个字符长度(“ BusinessCombinationRecognizedIdentifiableAssetsAcquiredAndLiabil ”)并导致重复条目异常。
请帮我解决这个问题?如果需要更多详细信息,请告诉我..