2
RavenDB (빌드 # 888)에 엔티티가 저장되어 있습니다. 새로운 버전의 응용 프로그램과 연결된 데이터베이스 마이그레이션으로 인해 ID를 변경해야합니다. 이 코드의 결과RavenDB에 저장된 데이터의 마이그레이션
public bool Migrate()
{
using (var session = _store.OpenSession())
{
var users = session.Query<User>().ToList();
foreach (var user in users)
{
user.Id = user.Email;
}
session.SaveChanges();
}
}
실행 예외 : 이
Status: System.InvalidOperationException: Entity App.Models.Entities.User had document key 'mydomain-mylogin' but now has document key property '[email protected]'.
You cannot change the document key property of a entity loaded into the session
at Raven.Client.Document.InMemoryDocumentSessionOperations.CreatePutEntityCommand(Object entity, DocumentMetadata documentMetadata)
at Raven.Client.Document.InMemoryDocumentSessionOperations.PrepareForEntitiesPuts(SaveChangesData result)
at Raven.Client.Document.InMemoryDocumentSessionOperations.PrepareForSaveChanges()
at Raven.Client.Document.DocumentSession.SaveChanges()
이
방법이
을 수행 할 수 있습니다 나는 내가 사용하고 샘플 기능을 작성했습니다?
ID 필드는 문서의 중요한 부분입니다 그것을 찾는 데 사용되는 키. 그래서 그것이 당신이 그것을 바꿀 수없는 이유입니다. –
새 문서를 만든 다음 이전 문서를 삭제하는 것이 가장 쉬운 방법입니다. –
감사합니다. 몇 분 전에 그 일을 해낸 것 같습니다. 문안 인사. – jwaliszko