I have a question about how to map a foreign key ID with NHibernate mapping file. eg. I have the following classes:
class Topic {
public long ID {get; set;}
public string Name {get; set;}
}
class Post {
public long ID {get; set;}
public string Title {get; set;}
public string Content {get; set;}
public long TopicID {get; set;} // This is the FK refers to the Topic entity
}
The Post entity doesn’t reference the Topic directly, it only references the Topic by the TopicID as show above. However seems that NHibernate <many-to-one> mapping will only map the Topic as an entity in the Post, but I what I want is the TopicID FK, not the Topic entity. Could anybody help me on this?
Many thanks!
You can just declare the TopicID as a property, and not a
many-to-one.