views:

40

answers:

1

Using NHibernate I need to insert an entity into a database that has a child entity. Example:

public class Reservation
{
    public int Id { get; set; }
    public Service Service { get; set; }
}

public class Service
{
    public int Id { get; set; }
}

I need to create a new Reservation and insert it. However, when constructing the Reservation for insertion, I don't have the Service entity, but I do have the Service's Id value. Is there a way to insert my reservation without fetching the Service first?

+4  A: 

You can use NHibernate's Load method. This will create a proxy for the Service object, but it will not actually hit the database. See this blog post for the difference between load and get.

PhilB
Perfect!!!!!!!!!!!!
Ronnie Overby