N
N
nordwind20132019-01-21 21:44:47
.NET
nordwind2013, 2019-01-21 21:44:47

How to remove all many-to-many relationships of Entity FrameWork?

I'm trying to update collections in some class, I do everything with one context object. But the database is not updated. Tried everything in the world. Help out. Thank you.

public VideoMaterial GetEntityNotLazyLoad(int id)
        {
            var result = this.DB.VideoMaterials
                 .Include(vm => vm.Actors)
                 .Include(vm => vm.FilmMakers)
                 .Include(vm => vm.Countries)
                 .Include(vm => vm.Genres)
                 .Include(vm => vm.Themes)
                 .Include(vm => vm.Pictures)
                 .SingleOrDefault(vm => vm.ID == id);
            return result;
        }

        private void ClearAllRelations(VideoMaterial material)
        {
            if (material == null)
            {
                return;
            }
            material.Actors.Clear();
            material.FilmMakers.Clear();
            material.Genres.Clear();
            material.Pictures.Clear();
            material.Themes.Clear();
            this.DB.SaveChanges();
        }
        ClearAllRelations(GetEntityNotLazyLoad(1))

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question