Understandable but many of the issues you get with NH (using Identities generated by a DB for example) you can run into with other ORM's or ORM-like products such as Linq-SQL. Fabio (quite understandably) has a thing against DB identity and will usually be quite aggressive against it and not always explain himself fully for someone struggling with new concepts. He has an awful lot to do though and English isn't his first language so we're patient with him :)
NH is a big learning curve IMO but when you finally get your head around it, it's usually worth it. Maybe consider it for your next project taking into account what you have learnt from this one. One of the things you quickly do is to dump DB identity and use HiLo or GUID COMB - i.e. let NH generate your keys for you. And to explain your issue, NH always goes to the DB for a query. I suspect this is for performance reasons as how can it search its cache on any number of unknown (by the NH designer) parameters that a developer will provide? It would just be too slow. Therefore it will ONLY go to the cache where you provide an ID via a non-criteria call (e.g. Load). It's the only way that I can see it performing. Also, who is to say that an object you search on by (e.g. name) is the same object as you added to the cache previously. You may *know* its the same because you understand the logic, but NH does not. Therefore it needs to go to the DB to ensure it has the latest view of the DB world - which ultimately is what NH is all about. I'm a little hazy as its been a while since I used DB identity with NH but I think that in your case, you will not get an ID on the save as you have told NH to get the key from the DB. As you have worked out, a save does not save to the DB but saves to the cache (to be precise, adds it to the current Unit of Work). NH will only get the ID when you Flush the cache (or alternatively I think it will also do it when you Save within a transaction). Can you flush after the save or something similar? If not then, tbh, it sounds like you're not really using NH effectively and need to make compromises as a result. Just like you'd have to to use Linq-SQL (inherit from special classes) or ADO.NET (no in-built ORM mapping at all). Good luck. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
