System.NotSupportedException: Invalid operation - delete not allowed

System.NotSupportedException: Invalid operation - delete not allowed

Old forum URL: forums.lhotka.net/forums/t/6673.aspx


danielw posted on Wednesday, March 25, 2009

I have created a silverlight remote data portal app which is working fine.
We now have a need to delete business base objects.

But keep getting System.NotSupportedException: Invalid operation - delete not allowed error.

Code is as follows

public static void DeleteEmployee(Int32 sEM_ID,EventHandler<DataPortalResult<Employee>> handler)
{
DataPortal<Employee> dp = new DataPortal<Employee>();
dp.DeleteCompleted += handler;
dp.BeginDelete(
new Criteria(sEM_ID));
}

and then

protected override void DataPortal_Delete(object Crits)
{
Criteria crit = (Criteria)Crits;
using (SqlConnection cn = new SqlConnection(DataBase.MakingSpaceOperationsConnection))
{
cn.Open();
using (SqlCommand cmd = new SqlCommand("JM_Employee_Delete", cn))
{
ApplicationContext.LocalContext["dpConnection"] = cn;
ApplicationContext.LocalContext["dpCommand"] = cmd;
cmd.CommandType = System.Data.
CommandType.StoredProcedure;

cmd.Parameters.AddWithValue("@SEM_ID", crit.SEM_ID);
onDeletePre(cmd, EventArgs.Empty);
cmd.ExecuteNonQuery();
onDeletePost(cmd, EventArgs.Empty);

}}}

It gives no error and compiles but when run using

Employee.DeleteEmployee(1, DeleteEmployees);

It returns the Delete not allowed error. We have stepped throught the code and cannot see anything wrong we seem to have overridden the method successfully.

 

Has anybody got any ideas

Cheers

Daniel

ajj3085 replied on Wednesday, March 25, 2009

Don't override; create an overload that accepts a Criteria object.

danielw replied on Thursday, March 26, 2009

Thanks for the reply.

I tried that at first but it did not work. Putting it back gives
However after more digging I have found that it works fine if I use the singlecriteria but if I try to use my own Criteria it gives the  Invalid operation - delete not allowed error

I guess I might be setting up my criteria wrong but it works for the fetch fine

Anybody else got any ideas

Cheers
Daniel

ajj3085 replied on Thursday, March 26, 2009

I think you'll need to put you factory method, dataportal method, and entire criteria class.

Copyright (c) Marimer LLC