How do I delete this method

Asked

Viewed 71 times

0

I can’t call the methods: DeleteOnSubmit and also the method: DeleteObject. See below my code and how I delete it.

public static void deletaRuptura(int _idmotivo)
        {
            RupturaEntities db = new RupturaEntities();

            try
            {
                var monta_arvore = (from rup in db.Ruptura
                                    join ap in db.Apresentacao on rup.Codigo_Apresentacao equals (ap.Codigo_Apresentacao)
                                    join mo in db.Motivo on rup.IDMotivo equals (mo.IDMotivo)
                                    join pdv in db.PDV on rup.CodigoPDV equals (pdv.CodigoPDV)

                                    where rup.IDMotivo != _idmotivo

                                    //group rup by new { rup.IDRuptura} into gr

                                    select new 
                                    {
                                        rup.IDRuptura,
                                        rup.DataRuptura,
                                        rup.IDMotivo,
                                        rup.Motivo.Motivo1,
                                        rup.IDOrigem,
                                        rup.CodigoPDV,
                                        rup.PDV.UF,
                                        pdv.Cidade,
                                        CnpjDescricao = pdv.Cnpj + " - " + pdv.Descricao,
                                        rup.Codigo_Apresentacao,
                                        ap.Unidade_Negocio,
                                        ap.Codigo_Unidade_Negocio,
                                        ap.Franquia,
                                        ap.Familia,
                                        ap.Descricao
                                    }).ToList().OrderBy(r => r.IDMotivo);

                foreach (var item in monta_arvore)
                {
                    //db.DeleteOnSubmit(item);
                }
            }
            catch (Exception ex)
            {
            }
        }

That’s the mistake that comes:

'System.Data.Entity.DbSet<Ruptura.Models.Ruptura>' does not contain a definition for 'DeleteAllOnSubmit' and no extension method 'DeleteAllOnSubmit' accepting a first argument of type 'System.Data.Entity.DbSet<Ruptura.Models.Ruptura>' could be found (are you missing a using directive or an assembly reference?)
  • can edit your question with the db.Deleteonsubmit(item) method? This is where the exception is raised?

1 answer

1

As you return an anonymous type, I believe the simplest would be you can run a T-SQL command:

var rowsAffected = db.Database.ExecuteSqlCommand("DELETE FROM RUPTURA WHERE IDRUPTURA = @IDRUPTURA", item.IDRuptura);
  • It’s all mine is in LINQ and Entity, so an Ado.Net would be totally out of context. It would get very messy.

  • This is the problem. You won’t be able to use it the way you want because your context doesn’t know the "entity" that you like Anonimous type.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.