1
자식 엔티티에 대한 참조를 자동 매핑 (Automapper 사용)하는 기술을 가진 사람이 있습니까?엔티티 프레임 워크에서 EntityKeys로 자동화
class AddressModel
{
int Id;
string Street;
StateModel State;
}
class StateModel
{
int Id;
string Name;
}
내가 엔티티 프레임 워크에 해당하는 개체에 매핑하여 저장소에이 통과 : 그래서 나는 뷰 모델을 말한다. 오토 맵핑 할 때 AddressModel.State.ID를 AddressEntity.StateReference의 EntityKey로 자동 매핑하려고합니다. 그래서 손으로 만들어진 코드는 다음과 같습니다 automapper은 EF의 동등한에 Address.State.Id를 할당 할 때
addressEntity.Id = AddressModel.Id;
addressEntity.Street = AddressModel.Street
addressEntity.StateReference.EntityKey = new EntityKey("MyDB.States", "Id", AddressModel.State.Id);
물론, 예외가 발생합니다.