Thanks for all this info. It is invaluable. On Sat, Jul 18, 2009 at 12:24 AM, Huw Jenkins<[email protected]> wrote: > > Hi Craig, > > I've worked with silverlight 2 and nhibernate. I didn't find it too > bad. As silverlight can only reference assemblies that use the > silverlight framework what I did was make two project files which > pointed to the same model classes. One project was a standard .net > class library the other project was a silverlight class libary. My web > service application then referenced the standard .net class library > and the silverlight app referenced the silverlight project file. > > E.G > DomainModel.csproj > DomainMode_Silverlight.csproj > (both proj referenced the same .cs files containing my domain model) > > I then used WCF and the DataContract and DataMember attributes to > create my DTOs. There are some restrictions on the silverlight 2 wcf > implementation which meant all my domain objects had to have empty > publicconstructors for the serialisation to work and I think all > serialised properties needed to be public as well. What I sometimes > did if I really didn't want them to be > public in the standard class library (which was also used by other > applications) was to use #if SILVERLIGHT so only the silverlight > project had the public versions. > > The only thing that I then had to be careful with was lazy loading and > the serialisation process. For instance say you have an author object > which has a list of books. You were lazy loading the list of books. If > you're web method got all authors > > public Author GetAuthor( string authorname ) > { > ISession session = NHibernateSessionManager.Instance.GetSession(); > Author author = session.Get<Author>( authorname ); > return author; > } > > Assuming you've told WCF to serialise the books list the above will > throw an exception during serialisation as the session is unacceesible > once the serialisation process begins. In order to solve this I would > just do a call to all the objects that I wanted serialised to ensure > they had been loaded. (Or i disabled lazyloading). > > e.g. > public Author GetAuthor( string authorname ) > { > ISession session = NHibernateSessionManager.Instance.GetSession(); > Author author = session.Get<Author>( authorname ); > IList<Book> books = author.Books; <-- this just ensures that the > query to the lazy loaded Books is called > return author; > } > > On the silverlight side I then get my actual author object which I can > then just hook up to the controls using M-V-VM pattern which works > quite nicely. > > The other problem I had with silverlight 2 was that whilst it was > possible to use json serialisation you had to write the calls to the > serialisation process yourself. So I just stuck with Xml so I didn't > have to worry about serialisation at all. I beleive silverlight 3 you > can specificy on the web service proxy in silverlight that you want > the transport to be in JSON. > > Beyond that it all worked quite nicely. Saving was just a question of > sending the domain objects I wanted back through the web service and > calling save on the session as normal. > > EG > public void SaveAuthor( Author author ) > { > ISession sess = NHibernateSessionManager.Instance.GetSession(); > using( ITransaction transaction = session.BeginTransaction() ) > { > session.Save<Author>( author ); > transaction.Commit(); > } > } > > Whilst I've been able to rely solely on WCF to create my DTOs there > are probably going to be times when I need to manually write and > convert them. But then that's just a question of writing the > converters. But so far I haven't hit any real problems with it. > Basically a combination of using the Model-View-ViewModel and WCF has > made using NHibernate and Silverlight 2 reasonably straightforward. > The only thing is you need a silverlight project that contains the > domain model. > > Anyway hope that all makes sense and is useful, other people may have > found better ways of doing it but that's how I'm currently using > NHibernate with Silverlight 2. > > Huw > > > On Jul 17, 5:12 am, Craig van Nieuwkerk <[email protected]> wrote: >> I am about to start a new project and wondering if anyone has got >> nHibernate to work well with Silverlight 3 & .NET RIA Services. There >> are not many references on the web about it, and the ones available >> don't give me much confidence it will be a nice solution. >> >> Craig. > > > >
--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
