다음 클래스가 있습니다.객체의 MongoDB 직렬화/직렬화
public class User : System.Security.Principal.IPrincipal
{
public int _id { get; set; }
public IIdentity Identity { get; set; }
public bool IsInRole(string role) { }
}
나는 다음과 같은 코드를 사용하여 MongoDB를이 클래스의 인스턴스를 저장하려고 해요 : 나는 DB에서 개체를 검색 할 때, 저장 한 후
new MongoClient("")
.GetServer()
.GetDatabase("")
.GetCollection("")
.Save<User>(
new User
{
_id = 101,
Identity = new GenericIdentity("uName", "Custom")
}
);
을; Identity.Name
및 Identity.AuthenticationType
의 값은 여전히 null
입니다.
직렬화/직렬화 해제 지시 사항이 없기 때문입니까?
클래스 맵을 사용해 보았지만 문제는 동일하게 유지됩니다.
BsonClassMap.RegisterClassMap<User>(cm =>
{
cm.AutoMap();
cm.MapIdProperty(c => c._id);
cm.MapProperty(c => c.Identity);
});
편집
이는 DB에 저장된 얻을 것입니다 :
{
"_id" : 101,
"Identity" : {
"_t" : "GenericIdentity",
"Actor" : null,
"BootstrapContext" : null,
"Label" : null
}
}
사용자를 저장 한 후에는 데이터베이스에서 어떻게 보입니까? –
@CraigWilson, 질문이 업데이트되었습니다. – dan
나는 문제가 우리가 GenericIdentity를 재수화할 수있는 방법이 없다고 생각한다. GenericIdentity 클래스의 클래스 맵을 등록하여 다시 만들 필요가있는 속성, 특히 Name과 AuthenticationType을 유지해야합니다. 그런 다음 작성자를 매핑하여 다시 생성해야합니다. –