Search code examples
wcf-ria-services

RIA Services Entity Deletion


I have a DomainService which I am trying to delete records from.

Assuming the following rough code server-side method:

public IQueryable<Employee> GetAllEmployees()
{
    DataLoadOptions loadOpts = new DataLoadOptions();
    loadOpts.LoadWith<Models.Employee>(e => e.PhoneNumber);

    this.DataContext.LoadOptions = loadOpts; 
    return this.DataContext.Employees;
}

This means that when I load all my employees, all their Phone Numbers are included.

I can do the following client side code, with phoneNumber being an entity:

domainContext.Employees.PhoneNumbers.Remove(phoneNumber);

This, as I understand it, removes the relationship between Employee and PhoneNumber entitities, but what I really want is the complete removal of PhoneNumber from the database. How can I accomplish this?


Solution

  • Assuming PhoneNumbers is also an Entity on the Client side, then you can do the following:

    domainContext.Employees.PhoneNumbers.Remove(phoneNumber); // remove relationship
    domainContext.PhoneNumbers.Remove(phoneNumber); // remove entity