开发者

nhibernate insert question - have id but not entity object

开发者 https://www.devze.com 2023-01-16 16:34 出处:网络
Using NHibernate I need to insert an entity into a database that has a child entity. Example: public class Reservation

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消