Click here to Skip to main content
15,885,179 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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...

C#
private ParentMetadata()
            {
            }

            [Include]
            public Child Child{ get; set; }
            public string desc { get; set; }

}



Service Code for Parent


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



And in the insert method i have:


C#
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
Updated 25-Jul-12 9:48am
v3
Comments
Karl Sanford 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 25-Jul-12 15:48pm    
Updated the question, thx :D
Karl Sanford 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 25-Jul-12 16:21pm    
Yes, it gives an error saying that obj.Child dont have an add method.

1 solution

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.
 
Share this answer
 
Comments
renabee 25-Jul-12 20:36pm    
thanks, it worked creating one service to all tables.
Christian Amado 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900