Hi,
I'm new to NHibernate and have a litte problem with my foreign keys in code.
I have mapped the foreign keys to object references in C#, which is working great. But I wonder what is the best way to set that reference if you only know the ID of the referenced object and don't have a object instance.
One way would be to load the object instance with the ID from the database. But that causes a unneeded select statement, because I don't really want to know anything about the referenced object except it's ID.
Then I tried to add a second property to my business objects which represent my foreign keys. So I had the reference to the foreign object and the foreign key as a int property. But I couldn't find a way to say NHibernate that these two properties map to the same column. And because of that inserting and updating didn't work. Have I missed something here or is that a wrong way to do it?
Right now I just create a new object myself and set it's ID like this:
Code:
child.Parent = new Parent { ID = parentID };
Is there any better way to do it?
NHibernate version: 1.2.1.GA
.NET 3.5
ASP.NET Website, one NHibernate-Session per Request