Lazy Loading in NHibernate

前端 未结 5 1045
不知归路
不知归路 2021-01-19 10:47

If a Customer has many Orders attached to them. How would you lazy load the Orders List using NHibernate.

Is it something that needs to be set up mapping file? any

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-19 11:13

    Do you want that the Customer entity has a property that contains all his Orders ? I think that this can be quite a large collection.
    I think that, the question you'll have to ask yourself is:
    How many times do I really need to have direct access to the Orders of a Customer ?

    Perhaps, in this case, you don't want to have a bidirectional association ? Perhaps you don't want to have an Orders collection in your Customer class.
    Then, I would add a method to my Order Repository, which has the following signature:

    IList GetOrdersForCustomer( Customer c );
    

    But, I don't know if this is feasible for your situation.

提交回复
热议问题