Hi
I am using NHibernate entities within Silverlight 3 application using RIA services. There is one problem that I am facing:
All real life projects have their many to one associations presented with a class reference (for example: IssueClassesEntity parent) and never with an id (int ParentId).
For example:
Code:
1. [DataContract]
2. public partial class IssueTypesEntity : GenericBaseEntity
3. {
4. protected int _Id;
5. private String _Name;
6. private IssueClassesEntity _IssueClass;
7.
8. [Key]
9. [DataMember]
10. public virtual int Id
11. {
12. get { return _Id; }
13. set { _Id = value; }
14. }
15.
16. // Parent issue Class (NOT an int ID)
17. [Include]
18. [External]
19. [Association("IssueTypes_IssueClasses", "Id", "Id", IsForeignKey = true)]
20. [DataMember]
21. public virtual IssueClassesEntity IssueClass
22. {
23. get { return _IssueClass; }
24. set { _IssueClass = value; }
25. }
26.
27. [DataMember]
28. public virtual String Name
29. {
30. get { return _Name; }
31. set
32. {
33. _Name = value;
34. }
35. }
36. }
The problem is that the set property for parent IssueClass (many to one association) in IssueTypesEntity proxy does not get generated. Then the sample for updating and inserting an issue type record simply does not work.
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.cs
void 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 because of the above problem.
Can this be fixed and how? Thank you for your help.
Regards