Ca4nul @ facebook Ca4nul @ Twitter
Forum announcement: $$ Top Contributors Contest (March 2010) - Win Instant extra Cash $$
Welcome Guest Search | Active Topics | Members | Log In | Register

Silverlight, RIA, NHibernate, Many to one association Options
adam
Posted: Tuesday, July 14, 2009 4:06:04 AM
Rank: Advanced Member
Groups: Member

Joined: 4/3/2008
Posts: 142
Points: 432
Location: London
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
Sponsor
Posted: Tuesday, July 14, 2009 4:06:04 AM
David
Posted: Tuesday, July 14, 2009 4:10:27 AM
Rank: Advanced Member
Groups: Member

Joined: 2/24/2009
Posts: 38
Points: 114
Location: USA
I have some idea why it doesn't work, and it may be caused by a current limitation in how the DomainDataSource works. Specifically, it expects your Product entity to have a foreign key that it can set, while in pure POCO like this you don't have one.

Note that setting the 'otherKey' to "Id" in the Association (in Product) is not quite correct. What it should really be is "Category.Id", though even that wouldn't work right now.

I'm quite interested in getting this scenario working, but I haven't played with NHibernate enough to get there. If you can send us a more complete sample, we can try to work together in making this work.

thanks,
David
hightech
Posted: Friday, July 17, 2009 12:25:31 AM
Rank: Advanced Member
Groups: Member

Joined: 9/6/2008
Posts: 61
Points: 183
Please share complete sample, it will make things easier and fast to work.

Microsoft: "You've got questions. We've got dancing paperclips
Test Management
Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

ASPNET Theme created by Boskone (Dan Ferguson)
Powered by Ca4nul.Com
Copyright © 2003-2006 Yet Another Forum.net. All rights reserved.
This page was generated in 0.088 seconds.