I have combination of RIA services and nHibernate. nHibernate is configured to use identity on database side. So new Entities are sent with 0 for id. nHibernate works as it should. It updates generated keys form database and updates entites.
I have example with compositional hierarchy. My entity is complex it has two collections.
InvestObject
- MaterialItems
- WorkItems
I work with this structure in one unit of work. Geting and showing data in Silverlight app is no problem. But if I try to add more than one item in MaterialItems collection on client side, when saving I get this error:
Submit operation failed. Invalid ChangeSet : Only one entry for a given entity instance can开发者_Go百科 exist in the ChangeSet. at System.ServiceModel.DomainServices.Server.ChangeSet.ValidateChangeSetEntries(IEnumerable
1 changeSetEntries) at System.ServiceModel.DomainServices.Server.ChangeSet..ctor(IEnumerable
1 changeSetEntries)
There is a quick fix on client side, just to generate some dummy negative ids, for Material. This works for RIA and save is propagated to server side. But then nHibernate fires error, beacuse it expects 0 for all new Ids not a given value ( ). So this is not OK.
Finally I tricked nHibernate by reseting back all new Ids to 0. But this does not make me happy. It is messy ugly solution.
Please help
It's been a while since I've done this so the details are hazy but I think you basically can't use IDs that are generated in the DB with RIA services. We used the HiLo algorithm instead.
精彩评论