Fluent NHibernate Mapping Problem (Override)
I have tried to make an inheritation mapping. There are two
alternative. One alternative is with JoinedSubClass
(that is
deprecated and give me a warning) and the other and newer is with
SubClassMap
.
But I get an error that I have duplicate entity/object mapping. What could be the problem?
With the JoinedSubClass
it runs. Here are the Codes of my two Objects
and the MappingFile
with JoinedSubClass
which runs, later there are
the code of my mapping file with "SubClassMap" which doesn't run....
Objects:
public class Person {
public virtual int Id { get; private set; }
public virtual string Vorname { get; set; }
public virtual string Nachname { get; set; }
public virtual string Email { get; set; }
public virtual Adresse Adresse { get; set; }
public Person() {
}
}
public class PersonQuelle : Person, IQuelle {
public virtual string Beschreibung { get; set; }
public virtual Institution Institution { get; set; }
public virtual IList<MediaDatei> MediaDateien { get; set; }
public PersonQuelle() {
Med开发者_如何转开发iaDateien = new List<MediaDatei>();
}
public virtual void HinzufuegenMediaDatei(MediaDatei mediaDatei) {
mediaDatei.PersonQuelle = this;
MediaDateien.Add(mediaDatei);
}
public virtual void LoeschenMediaDatei(MediaDatei mediaDatei)
{
mediaDatei.PersonQuelle = null;
MediaDateien.Remove(mediaDatei);
}
}
Mapping Files:
public class PersonMap : ClassMap<Person> {
public PersonMap() {
Id(x => x.Id);
Map(x => x.Vorname);
Map(x => x.Nachname);
Map(x => x.Email);
References(x => x.Adresse);
JoinedSubClass<PersonQuelle>("personQuelle_Id", m => {
m.Map(c => c.Beschreibung);
m.References(c => c.Institution);
m.HasMany(c => c.MediaDateien).Inverse().Cascade.All();
});
JoinedSubClass<MMAdminBenutzer>("mmAdminBenutzer_Id", m =>
{
m.Map(c => c.Kuerzel);
m.Map(c => c.Passwort);
m.Map(c => c.Benutzerrolle);
m.HasMany(c => c.MediaDateien).Inverse().Cascade.All();
m.HasMany(c => c.Kategorien).Inverse().Cascade.All();
});
}
}
But why it doesn't run when I do that with the same Objects however with this mapping file??
Mapping File with SubClassMap
:
public class PersonMap : ClassMap<Person> {
public PersonMap() {
Id(x => x.Id);
Map(x => x.Vorname);
Map(x => x.Nachname);
Map(x => x.Email);
References(x => x.Adresse);
}
}
public class PersonQuelleMap : SubclassMap<PersonQuelle>
{
PersonQuelleMap()
{
Map(c => c.Beschreibung);
References(c => c.Institution);
HasMany(c => c.MediaDateien).Inverse().Cascade.All();
}
}
It's hard to tell without the error that you get, but I think you are missing a call to KeyColumn("personQuelle_Id")
in your SubclassMap
.
精彩评论