1

I am trying save a new Person to the database. My code compiles just fine but when I run it I get an error at at the .Add().

The error says, "This EntitySet of Type 'Diavik.DataAccess.Person' does not support the 'Add' operation."

This is a SilverLight application and this file is the App.xaml.cs.

Here is my code:

private void OnGetPerson_Completed(LoadOperation<Person> operation)
{
    Person person = operation.Entities.SingleOrDefault();

    if (person == null)
    {
        person = new Person()
        {
            FirstName = WebContext.Current.User.FirstName,
            LastName = WebContext.Current.User.LastName,
            IlluminatorLogin = WebContext.Current.User.Name
        };

        Context.Persons.Add(person);
    }

    Context.SubmitChanges(submitOp =>
    {
        // Some Stuff
    }, null);
}

Thank you for your help,

Aaron

1
  • 1
    How is your domain service looks like? Do you have an [Insert] method? Commented Jun 12, 2013 at 20:06

1 Answer 1

6

You need to have a method in your Domain Service marked as an [Insert] method. It must be public, void, and take only one parameter (the Person object).

Something like this:

[Insert]
public void InsertPerson(Person p)
{
    ObjectContext.Persons.AddObject(p);
}

This code may not be exactly what you need because I don't know what your domain service looks like, but you get the general idea.

You don't actually need to call this service method directly, the RIA Services link handles the translation between this method and when you call Persons.Add() on the client side. It just has to exist, that's all.

Sign up to request clarification or add additional context in comments.

1 Comment

Ahh! I did Attach by mistake. Stupid 5 year old project.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.