tags:

views:

344

answers:

0

repository :

public IQueryable<Feature> GetAllFeaturesByLinkAndParentID(int id)
    {
       return from gp in db.Features where gp.int_ParentId == id && gp.bit_IsLink == false
                              select gp;
    }

controller:

int GetFeatureId = Convert.ToInt32(collection["FeatureList"]); //dropdown

     var DeleteFeature = FeatureRepository.GetAllFeaturesByLinkAndParentID(GetFeatureId);
                     _db.Features.DeleteAllOnSubmit(DeleteFeature);
                    _db.SubmitChanges();

how will i remove the error Cannot remove an entity that has not been attached in this code

var r = from gp in _db.Features
where gp.int_ParentId == GetFeatureId && gp.bit_IsLink == false
  select gp;
              //      return r;
                  //   var DeleteFeature = FeatureRepository.GetAllFeaturesByLinkAndParentID(GetFeatureId);
                    _db.Features.DeleteAllOnSubmit(r);
                    _db.SubmitChanges();

Directly inserting the Linq works(What is wrong with the above seperate code)