How to delete an Entity record with a linq query?

0

What I want is to delete an entity framework record through a linq query that only gives me a slight error:

linq query code:

var context = GetDbContext();

        var listadoV = from Ar in context.archivo
                              where Ar.url.Contains(elemento)
                              select new FileNedera()
                              {
                                  Url = Ar.url,
                              };

        context.archivo.Remove(listadoV);
        context.SaveChanges();

You mark me an error in the following line context.archivo.Remove(listadoV); and it tells me the following:

Cannot convert from system.Linq.IEqueryable to Ned4AccesData.Archivo

Also try it this way:

context.BloqueoExcursion.RemoveRange(cSelect);
context.SaveChanges();
    
asked by David 22.06.2018 в 23:44
source

1 answer

0
var context = GetDbContext();

var listadoV = from Ar in context.archivo
                   where Ar.url.Contains(elemento)
                   select Ar;

context.archivo.Remove(listadoV);
context.SaveChanges();

Explanation:

In your code, when you use select new FileNedera() , you are changing the original structure because you create a new kind of the filtering you are doing.

    
answered by 23.06.2018 в 00:10