I'm working on a Silverlight 4 app using RIA and entity framework that is connecting to SQl Server 2008.
I wrote a service method to delete some entities, I can step into the code and watch it execute on the two entities I expect to delete, but when I submitchanges the records don't delete.
I'm using a DomainContext to excute the call, and the context doesn't appear to lose scope and it's the only one so I'm not call two. I'm stumped
code from my orginal attempt one is below
AppDomainContext ctx = new AppDomainContext();
ctx.DeleteAgencyLogoForAgency(agencyId);
ctx.SubmitChanges((op) =>
{
if (op.HasError)
{
Debug.WriteLine(op.Error.Message);
}
}, null);
AtempT two:
AppDomainContext ctx = new AppDomainContext();
ctx.Load(ctx.GetAgencyLogosByAngencyIdQuery(agencyId), result =>
{
if (result.HasError)
{
MessageBox.Show(result.Error.Message.ToString());
}
var loadedGroup = result.Entities.ToArray();
foreach (var item in loadedGroup)
{
ctx.AgencyLogos.Remove(item);
}
}, null);
ctx.SubmitChanges();
The Service Method:
public void DeleteAgencyLogo(AgencyLogo agencyLogo)
{
if ((agencyLogo.EntityState == EntityState.Detached))
{
this.ObjectContext.AgencyLogos.Attach(agencyLogo);
}
this.ObjectContext.AgencyLogos.DeleteObject(agencyLogo);
}
[Invoke]
public void DeleteAgencyLogoForAgency(int agencyID)
{
foreach (AgencyLogo logo in GetAgencyLogosByAngencyId(agencyID))
{
DeleteAgencyLogo(logo);
}
}
Thanks in advance!