2 개의 테이블을 결합하고 싶습니다. 그들은 외래 키를 가지고 있지 않지만 동일한 내용을 가진 컬럼을가집니다. 스키마를 변경할 수 없으며 여기에 간단한 예가 나와 있습니다.nhibernate가있는 외래 키가없는 2 개의 테이블과 코드로 매핑하기
public class Person{
public virtual string Name{get;set;}
public virtual int Id{get;set;}
public virtual char Gender{get;set;} #this one I want to connect
}
public class PersonMapping : ClassMapping<Person>{
public PersonMapping()
{
Id(x=>x.Id);
Property(x=>x.Name);
Property(x=>x.Gender);
}
}
public class Gender{
public virtual char ShortName{get;set;} #to this. So they are the same. When They are connected I want to access the Other properties of this class
public virtual int Id{get;set;}
public virtual string LongName{get;set;}
}
public class GenderMapping: ClassMapping<Gender>{
public GenderMapping()
{
Id(x=>x.Id);
Property(x=>x.ShortName);
Property(x=>x.LongName);
}
}
이제 모든 사람이 해당 성별을 갖고 싶어합니다. 그래서 나는 긴 이름을 찾을 수 있습니다. 나는 해결책이 this과 같다고 생각하지만 유창한 nhibernate를위한 것이다. 나는 또한 criterias 또는 이와 유사한 일을하는 것이 좋을 것입니다.
나는 이것이 내가 무엇이라고 생각 : 코드에 의해 매핑의 아주 좋은 설명이 있습니다
검색하지만 작동하지 않습니다. 그는 .... (Column)에서 참조 된 엔터티 'System.String'을 찾을 수 없습니다. 나는이 강령을 위해 무엇을 넣을 지 모른다. 그래서 예를 들어 그 참조를위한 전체 젠더 객체를 원한다면 어떻게 할 수 있습니까? – Iron
와우 죄송합니다. ** ShortName ** –
네, 시도 했어. 그는 짧은 이름을 찾을 수 없습니다 – Iron