От: | senglory | ||
Дата: | 19.02.21 06:48 | ||
Оценка: |
[Table("IncomingTransactions",Schema ="demo")]
public class Transactions
{
[Key]
[Column("tranId")]
[MaxLength(12)]
public string TranID { get; set; }
public class FamilyTeamSvcDbContext : DbContext
{
public DbSet<Transactions> Transactions { get; set; }
foreach (var tr in lstTrans)
{
var transactionAreadyInDB = ctx.Transactions
.Where(x => x.TranID == tr.TranID ).Any();
if (transactionAreadyInDB)
{
continue;
}
ctx.Transactions.Add(tr);
System.InvalidOperationException: The instance of entity type 'Transactions' cannot be tracked because another instance with the same key value for {'TranID'} is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the conflicting key values.
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IdentityMap`1.ThrowIdentityConflict(InternalEntityEntry entry)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IdentityMap`1.Add(TKey key, InternalEntityEntry entry, Boolean updateDuplicate)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.StartTracking(InternalEntityEntry entry)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(EntityState oldState, EntityState newState, Boolean acceptChanges, Boolean modifyProperties)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityGraphAttacher.PaintAction(EntityEntryGraphNode`1 node)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityEntryGraphIterator.TraverseGraph[TState](EntityEntryGraphNode`1 node, Func`2 handleNode)
at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.Add(TEntity entity)