Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# entity RIA Silverlight5 , +
Hi,
 
When creating the domain ria services, we should make one service for each table or one service for all tables??
 
I'm asking this cause i created one service for each table, and worked fine with simple tables. But now i'm having problems with Parent/child tables...
 
private ParentMetadata()
            {
            }
 
            [Include]
            public Child Child{ get; set; }
            public string desc { get; set; }
 
}
 

Service Code for Parent
 

public IQueryable<Parent> GetParent()
        {
            return this.ObjectContext.Parents.Include("Child");
        }
 

And in the insert method i have:
 

private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            Web.Services.ParentContext context;  
            context = new Web.Services.ParentContext();
            WMS.Web.Model.Parent obj = new WMS.Web.Model.Parent();
 
            Guid obj2 = Guid.NewGuid();
            obj.GUIDParent = obj2;
            obj.desc = descTextBox.Text;
            obj.Child.GUIDParent = obj2;
            obj.Child.desc = descTextBox.Text;
            context.Parents.Add(obj);
 
            try
            {
                context.SubmitChanges();
                MessageBox.Show("sucess");
 
                this.DialogResult = true;
 
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
                this.DialogResult = false;
            }
        }
 

I'm always getting an error saying that obj.Child is null
Posted 25-Jul-12 8:35am
renabee161
Edited 25-Jul-12 10:48am
v3
Comments
Karl Sanford at 25-Jul-12 15:33pm
   
What kind of problems are you having? We can't help if we don't know what's wrong.
renabee at 25-Jul-12 15:48pm
   
Updated the question, thx :D
Karl Sanford at 25-Jul-12 16:00pm
   
Could you try to initialize the Child property of the parent before you use it? Some thing like: obj.Child = new WMS.Web.Model.Child();
renabee at 25-Jul-12 16:21pm
   
Yes, it gives an error saying that obj.Child dont have an add method.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Is recomendable that you create one service for all tables. But this is not a limitation.
 
Have you got Navigation property on your Entity Framework Model?
 
Must have a relation in the model and Database of course.
 
Hope it helps.
  Permalink  
Comments
renabee at 25-Jul-12 20:36pm
   
thanks, it worked creating one service to all tables.
Christian Amado at 25-Jul-12 20:45pm
   
Sounds very good. Enjoy it! =)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 BillWoodruff 330
1 Mathew Soji 309
2 Maciej Los 295
3 DamithSL 225
4 Afzaal Ahmad Zeeshan 217
0 OriginalGriff 6,369
1 Sergey Alexandrovich Kryukov 5,973
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 4,025


Advertise | Privacy | Mobile
Web04 | 2.8.1411019.1 | Last Updated 25 Jul 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100