Перенос данных из Postgresql на сервер Microsoft Sql ⇐ C#
-
Anonymous
Перенос данных из Postgresql на сервер Microsoft Sql
i want to transfer data From postgre with context _rentContext to microsoft sql server with context _rentContextSql. In my program first I check if that record exists in _rentContextSql it doesn't add it to the _rentContextSql but in the end, when I want to save changes get the error "The instance of entity type 'UsersUser' cannot be tracked because another instance with the key value '{Id: 51e4b9f1-e5e3-4bd0-a8f2-513929e1b259}' is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached"
time = DateTime.Now.AddMinutes(-15); timeDateOnly = DateOnly.FromDateTime(time); var postgresUserData = _rentContext.UsersUsers.Where(u => u.DateJoined > time).ToList(); foreach (var user in postgresUserData) { var existing = _rentContextSql.UsersUsers.FirstOrDefault(u => u.Id.Equals(user.Id)); if (existing == null) { _rentContextSql.UsersUsers.Add(user); } else { _rentContextSql.Entry(user).State = EntityState.Detached; } } _rentContextSql.SaveChanges();
Источник: https://stackoverflow.com/questions/780 ... sql-server
i want to transfer data From postgre with context _rentContext to microsoft sql server with context _rentContextSql. In my program first I check if that record exists in _rentContextSql it doesn't add it to the _rentContextSql but in the end, when I want to save changes get the error "The instance of entity type 'UsersUser' cannot be tracked because another instance with the key value '{Id: 51e4b9f1-e5e3-4bd0-a8f2-513929e1b259}' is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached"
time = DateTime.Now.AddMinutes(-15); timeDateOnly = DateOnly.FromDateTime(time); var postgresUserData = _rentContext.UsersUsers.Where(u => u.DateJoined > time).ToList(); foreach (var user in postgresUserData) { var existing = _rentContextSql.UsersUsers.FirstOrDefault(u => u.Id.Equals(user.Id)); if (existing == null) { _rentContextSql.UsersUsers.Add(user); } else { _rentContextSql.Entry(user).State = EntityState.Detached; } } _rentContextSql.SaveChanges();
Источник: https://stackoverflow.com/questions/780 ... sql-server
Мобильная версия