The comment is there http://nhforge.org/doc/nh/en/index.html#manipulatingdata-loading <http://nhforge.org/doc/nh/en/index.html#manipulatingdata-loading>"If the class is mapped with a proxy, Load() returns an object that is an uninitialized proxy and *does not actually hit the database until you invoke a method of the object*. *This behaviour is very useful if you wish to create an association to an object without actually loading it from the database*."
2009/11/9 Mohamed Meligy <[email protected]> > Super clear explanation and really really cool feature :) :). > > Although I'd see it as workaround at first the more I read in the > explanation the more I love this! > > Can this explanation go as the XML comment of the method or something? > > > Thanks a lot *Fabio *(sorry that I didn't understand what you meant at > first and assumed without checking), and Anne. > > > > Regards, > > -- > Mohamed Meligy > Senior Developer, Team Lead Backup (.Net Technologies) – Applications > Delivery - TDG > Injazat Data Systems > P.O. Box: 8230 Abu Dhabi, UAE. > > Phone: +971 2 6992700 > Direct: +971 2 4045385 > Mobile: +971 50 2623624, +971 55 2017 621 > > E-mail: [email protected] > Weblog: http://weblogs.asp.net/meligy > > > On Mon, Nov 9, 2009 at 12:02 PM, Anne Epstein <[email protected]> wrote: > >> Mohamed, >> See this post: >> >> http://ayende.com/Blog/archive/2009/04/30/nhibernate-ndash-the-difference-between-get-load-and-querying-by.aspx >> >> Summary- Here's what you do to get the behavior you're looking for: >> >> 1) retrieve your Category from your repository >> 2) assign this category to the product >> 3) save >> >> You might ask: "But won't that cause a db SELECT call in step 1?" *No*, >> not if you use the Load() method. Load() will create a proxy of your >> Category object with the id you specify, *without* getting the contained >> data of the Category from the db. Assign that proxy object to the >> product.Category. Save your product, and you *never* had to hit the db to >> get your Category. Of course, if you were to access one of the properties >> of Category in your code, NH would make a db call to get the values... but >> if you only do a straight Load() and assign the "retrieved" proxy to >> product.Category, it'll work exactly the way you want, no SELECTs, ony one >> INSERT statement. Next time you pull Product out of the db and access its >> Category, your relationship with this Category will come back out just the >> way you want. >> >> Anne >> >> >> >> On Mon, Nov 9, 2009 at 1:47 AM, Mohamed Meligy <[email protected]>wrote: >> >>> Well, what if I do not want to load the category? I know it sounds stupid >>> caring about only one more query it shouldn't be an optimization, but I was >>> just curious if it was possible. >>> >>> >>> Regards, >>> >>> -- >>> Mohamed Meligy >>> Senior Developer, Team Lead Backup (.Net Technologies) – Applications >>> Delivery - TDG >>> Injazat Data Systems >>> P.O. Box: 8230 Abu Dhabi, UAE. >>> >>> Phone: +971 2 6992700 >>> Direct: +971 2 4045385 >>> Mobile: +971 50 2623624, +971 55 2017 621 >>> >>> E-mail: [email protected] >>> Weblog: http://weblogs.asp.net/meligy >>> >>> >>> On Mon, Nov 9, 2009 at 7:26 AM, Fabio Maulo <[email protected]>wrote: >>> >>>> product.Category = session.Load<Category>(theId); >>>> >>>> >>>> 2009/11/8 Mohamed Meligy <[email protected]> >>>> >>>> Let's say I have a mapping like this (using Fluent, sample made up for >>>>> the sake of the email) >>>>> >>>>> References(product => product.Category, "CategoryID"); >>>>> >>>>> where each One Category has zero to Many Products. >>>>> >>>>> Lets say I need to set the value of the Category.Id of the Product >>>>> directly without loading the Category object. I thought I could do >>>>> something >>>>> like: >>>>> >>>>> product.Category.Id <http://product.category.id/> = >>>>> int.Parse(ddlCategory.SelectedValue); >>>>> >>>>> (Code is OVER simplified for demoing here, yes, I have layering in my >>>>> application :)). >>>>> >>>>> Someone told me the proxy handles getting the value for >>>>> product.Category.Id <http://product.category.id/> (if exists) without >>>>> loading the category, so, I thought it may work when I SET the Id, but >>>>> what >>>>> happened is that it gave a NullReferenceException (makes sense of course). >>>>> >>>>> So, I was asking, is there another way of doing this ?? (whether or not >>>>> it is a right idea to do it at all please) >>>>> >>>>> >>>>> Thank you very much. >>>>> >>>>> Regards, >>>>> >>>>> -- >>>>> Mohamed Meligy >>>>> Senior Developer, Team Lead Backup (.Net Technologies) – Applications >>>>> Delivery - TDG >>>>> Injazat Data Systems >>>>> P.O. Box: 8230 Abu Dhabi, UAE. >>>>> >>>>> Phone: +971 2 6992700 >>>>> Direct: +971 2 4045385 >>>>> Mobile: +971 50 2623624, +971 55 2017 621 >>>>> >>>>> E-mail: [email protected] >>>>> Weblog: http://weblogs.asp.net/meligy >>>>> >>>>> >>>>> >>>> >>>> >>>> -- >>>> Fabio Maulo >>>> >>>> >>>> >>> >>> > > > > -- Fabio Maulo --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nhusers?hl=en -~----------~----~----~----~------~----~------~--~---
