locked
adding a entity in 1-to-1 join RRS feed

  • Question

  • i'm having a problem with adding a entity through the dataservices.

    database has 1->0..1 relationship from person to employee, adding the person is not a problem,
    but when adding the employee i'm getting an error.

     Data.Entities.SaveChanges(System.Data.Services.Client.SaveChangesOptions.None);
                var newemp = DataSVC.Employee.CreateEmployee(Entity.ID);
                newemp.Company = Company;
                newemp.Person = Entity;
                Data.Entities.AddToEmployee(newemp);
                Data.Entities.AddLink(Company, "Employee", Entity.Employee);
                Data.Entities.AddLink(Entity, "Employee", newemp);
                Data.Entities.SaveChanges(System.Data.Services.Client.SaveChangesOptions.Batch);

    the problem is with the addlink from entity(which is of type person) to newemp; the message states that addlink and deletelink can only be used on collection, i understand the message coz employee is not een collection but an single entity, same as in the database

    i've tried to 'set' the employee property on entity, no success (changes discarded)
    i've tried to 'set' the person in the employee object no success (complaining that it misses the expected person object)
    i've tried to 'set' the personID in the employee object no success (complaining that it misses the expected person object)
    i've tried to 'attachlink', will not work only on ready existing objects

    if you look at the table in the http://msdn.microsoft.com/en-us/library/cc668789.aspx is states that i should use addlink.... aaahhh
    can anyone help ??

    (for now i will do the workarond by inserting into db with plain old sql and then reloading the person en employee objects.... works but not what i had in mind.... :)

    Wednesday, January 14, 2009 7:45 AM

Answers

All replies