There is a mistake in the above code. I think it's easy guessable but to
avoid confusion here is the corrected part:
if(NHibernateUtil.IsInitialized(cart) == false)
{
NHibernateUtil.Initialize(cart);
}
the part [[ == false ]] was missed in the emailed version.
Thoughts ?
Regards,
--
Mohamed Meligy
Information Analyst (.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 Fri, Oct 30, 2009 at 10:25 AM, Mohamed Meligy <[email protected]>wrote:
> Session.Merge(..) did the trick for me. Very nice!!
>
> In a related question:
> Now if I want to intialie lets's say ShoppingCart.Items and rotate on them
> in other web requetses, you'd get an exception that the Proxy for each
> ShoppingcartItem is not intiailized because there is no session (because the
> session was closed by end of the first web request).
> Now, I have a similar scenario to this, and I work around it by writing
> some code similar to this (adapted to the given example of ShoppingCart):
>
> public static ShoppingCart UserShoppingCart
> {
> get
> {
> var cart = Context.Session[SessionShoppingCartKey] as
> ShoppingCart
> if(cart == null)
> {
> Context.Session[SessionShoppingCartKey] =
> cart = new
> ShoppingCartService().FindShoppingCartSomeHow(..../*whatever
> criteria*/....);
> }
>
> if(NHibernateUtil.IsInitialized(cart))
> {
> NHibernateUtil.Initialize(cart);
> }
>
> return cart;
> }
> }
>
>
> *Of course in real code I encapsulate the use of NHibernateUtil (just
> making it fit simple ShoppingCart sample), but I still want to know in
> general, Is this a good approach to do it ???*
>
> You mentioned there are other ways to manage this situation without using
> SessionState. Actually, the example I made up of my mind when writing the
> email to demonstrate sample use of SessionState (I real world distributed
> e-commerce engine I was responsible for ShoppingCart as a whole Module of
> the system in itself and distributed caching and really big story). Assume
> another example of saving some extended logged-in user information along the
> user session, *is there a better way tpo manage it ?*
>
>
> Regards,
>
> --
> Mohamed Meligy
> Information Analyst (.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 Fri, Oct 30, 2009 at 9:53 AM, Fabio Maulo <[email protected]> wrote:
>
>> session.Lock or Merge; Merge if the entity was saved in some moment.
>> btw there are some other options to manage that situation without use
>> HttpSession
>>
>> 2009/10/29 Mohamed Meligy <[email protected]>
>>
>> This mostly applies to web applications.
>>> Let's say I have an object "ShoppingCart" that is persisted both in HTTP
>>> SessionState and Database for some reason (let's say we want the user to
>>> find the cart available if he leaves the site and comes back later). Every
>>> time the user adds a "Product" to the "ShoppingCart", we want to add it to
>>> the "SessionState" already laoded in HTTP SessionState and then we save the
>>> "ShoppingCart" i dataabase.
>>>
>>> *We want to avoid loading the "ShoppingCart" from the database when we
>>> want to change some proprty or add some related object when we already have
>>> it loaded in HTTP SessionState,* but we are also using the typical
>>> "Single NHibernate ISession per HTTP Request" pattern, meaning the
>>> "ShoppingCart" is loaded from one NH ISession and changed in other different
>>> NH ISessions (since saved in HTTP SessionState, which is maintained across
>>> multiple HTTP Requests).
>>> *Will it be possible to have the object loaded from different NH
>>> ISession to be saved usig another ISession?*
>>>
>>> In Linq To Sql and Entity Framework you can theoretically Detach ad
>>> Re-Attach entity to different Data/Entity Context. I LLBLGen (Adapter not
>>> Self Servcing, cause the latter is just ACtiveRecord) the entity is
>>> generated with all required Proxy functionality that makes it self tracking
>>> making it easy to use without attaching to cetain Adapter.
>>> How about in NHibernate?
>>>
>>> Regards,
>>>
>>> --
>>> Mohamed Meligy
>>> Information Analyst (.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
>>
>> >>
>>
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---