0

I have an inheritance hierarchy where Owners, Tenants, Vendors and Agents are derived from People. In my WCF Data Service client, I want to use AddObject to create a new Owner, but I cannot find how to do this. When I try:

        var owner = new Owner()
        {
            FirstName = "Test"
            ,LastName = "Person"
            ,CheckName = "Test Person"
            ,PersonNo = "Test"
            ,UseFullNameForName = false
            ,TypeOfPerson = "Owner"
        };

        //Add
        context.AddObject("People", owner);
        context.SaveChanges();

the service throws a dynamic sql error. I am using WCF Services 5.4 with EF 4.5.

Alan Godfried
  • 95
  • 1
  • 8

1 Answers1

0

you should create the entity type of the table.

var person = new Person {
             FirstName = "Test"
            ,LastName = "Person"
            ,CheckName = "Test Person"
            ,PersonNo = "Test"
            ,UseFullNameForName = false
            ,TypeOfPerson = "Owner"
        };

context.Persons.AddObject(person);
context.SaveChanges();
Adrian Booth
  • 154
  • 1
  • 6
  • The derived types have additional information that is stored in tables other than the People table. If I do as you suggest, the related record in the other table will not be created. I would expect that WCF Data Services would have a way of adding a derived object without having to explicitly handle the relationship. – Alan Godfried Jun 19 '14 at 16:46