[EFCore] Shadow Property와 Backing Field
·
공부/EFCore
✅ Shadow Property class에는 있지만 DB에는 데이터가 없는 경우, [NotMapped] 혹은 .Ignore()로 해결한다. 반대로 DB에는 데이터가 있지만 class에는 없는 경우를 Shadow Property라고 한다. Shadow Property를 생성할 때는 .Property("프로퍼티이름") 으로 한다. 접근할때는 .Property("프로퍼티이름").CurrentValue로 한다. 망가진 아이템을 고친 날짜를 Shadow Property로 만들고 싶다고 하면, 우선 Data 생성란에 RecoveredDate를 추가해준다. db.Entry(items[0]).Property("RecoveredDate").CurrentValue = DateTime.Now; AppDbContext에도 ..