Skip to main content
Home Forums Silverlight Programming WCF RIA Services Silverlight 3, RIA, NHibernate, Many to one association
0 replies. Latest Post by sebastijanp on July 9, 2009.
(0)
sebastijanp
Member
2 points
11 Posts
07-09-2009 5:56 PM |
HiI am using NHibernate entities within Silverlight 3 application using RIA services. There is one problem that I am facing:I have many to one associations presented with a class reference.For example:
[DataContract]public partial class IssueTypesEntity : GenericBaseEntity{ protected int _Id; private String _Name; private IssueClassesEntity _IssueClass; [Key] [DataMember] public virtual int Id { get { return _Id; } set { _Id = value; } } [Include] [External] [Association("IssueTypes_IssueClasses", "Id", "Id", IsForeignKey = true)] [DataMember] public virtual IssueClassesEntity IssueClass { get { return _IssueClass; } set { _IssueClass = value; } } [DataMember] public virtual String Name { get { return _Name; } set { _Name = value; } }}
In the above case, the setter for IssueClass property in proxy client class is not generated.
After experimenting for a while...I found out the reason why the setter is not created.I have to declare Include attribute on the many to one association property. And not External (and especially not both).Then I found out (after two hours of reading blogs and forums) that in this case of declaring Include attribute, I have to have all my CRUD operations defined in same DomainService (IssueTypeServices) class. But even then the very very simple example isn't working since the data gets lost when calling the update operation service.I read this is the fact here:
http://www.scip.be/index.php?Page=ArticlesNET30&Lang=NL
It says: "In the Update or Insert method you will notice that the Place propertyis always null. When sending data to the server only the EntityKey ofthe EntityReference will be filled with the value of the FK property.So changing the Place property on client side won’t have any effect.You really need to modify the FK PlaceId property."
But the fact is (at least as I read RIA doc) that my association IS External, so this is how RIA works (no setter generation in this case) and here I am lost. In RIA's doc in 11. chapter there is a small example of calling some AddReference method. But I do not understand it.
After reading this last article, I think Association attribute (and Include) is not applicable/(makes no sense) to NHibernate entitites and that true NHibernate entities cannot be used in RIA environment.
It seem that we can use only value DTO objects. In this case the NHibernate users are excluded from using Silverlight. Am I wrong?
As I read RAI documentation it said, that you can have NHibernate entities, but there is no example on world wide internet.There are few trivial examples with simple properties as int, string, but they do not present a real life mapping.
I was reading a post on http://forums.asp.net/t/1434091.aspx and this is the same problem I guess.I created a demo project as David Fowler requested.You can download a working "NHibernate Silverlight" solution (with two sql scripts for sql server 2005) here:http://www.nconstruct.com/Samples/MyRiaBasic.zip- Unzip the file.- Open the solution VS 2008 (With Silverlight 3 and RIA services installed)- Rebuild solution- Run the two sql scripts to create a database by the name IssueTrackerSimple- Edit web.config for database string configuration if you must- Run the web application with SlIssueTrackerAppTestPage.aspx as a startup page- Please check the following methods marked with TODO: PROBLEM in MainPage.xaml.csvoid IssueTypesSelectionChanged(object sender, SelectionChangedEventArgs e) void OnIssueTypesContextLoaded(object sender, LoadedDataEventArgs e)void OnUpdateButtonClick(object sender, RoutedEventArgs e)void OnAddButtonClick(object sender, RoutedEventArgs e)Sample scenario:I am trying to edit issue-types entity represented in a grid on a left part of the screen. When clicking individual grid record, the editing appears on the right.The problem is that when selecting an issue type in a grid, the combo box for a parent issue class does not get selected. Updating an entity also becomes a problem. Can this be fixed and how? Thank you for your help.
Can Microsoft make this issue into working example?
Regards,Sebastijan