I'm while using Ado.Internet Entity Framework with ASP.Internet MVC.

During my MSSQL 2008 Database I've for instance the next simplified tables and relations:

 (Song) 1--* (Version) 1 -- 1 (VersionInfo)

Can you really instantly possess the linked Versions as well as their VersionInfo's erased after i remove an audio lesson?

Presently I'm using something similar to the next code, which quite a bit of manual work, since some tables have as much as 8 relations and individuals relations have subrelations too sometimes:

  db = new Database() //Entities
  Song song = db.Song.First();

  Song.Version.Load();

  foreach(Version version in Song.Version.ToList())
  {
       //Remove Song-Version Reference.
       song.Version.Remove(version);


       //Get The VersionInfo so we can delete it after we deleted the Version object.
       version.VersionInfoReference.Load();
       VersionInfo versionInfo = version.VersionInfo;

       //Now we can delete the Version Object.
       db.DeleteObject(version);
       //Now we can also delete the versionInfo, since the reference is gone.
       db.DeleteObject(versionInfo);

  }

  db.DeleteObject(song);

There has to be an simpler method of getting cascading down deletions. I already attempted setting the connection establishing MSSQL to Cascade when Removing, however it did not perform a factor... Did I miss something there?

Anyway, how can others solve this issue?

I attempted it having a simpler database, 2 tables, and discovered that cascade is just in the 1 side of the 1-many.

table A
id  - int
b_id - int 

table B
id - int

Relationship is placed from a.w_id and B.id. Remove rule is cascade.

After I remove A, B isn't erased. After I remove B, A is erased.

Issue is, I wish to have B erased after i remove A. I suppose that's only possible by hand.

You shouldn't do this within the Entity Framework. Preferred relational databases support ON CASCADE DELETE on foreign secrets which is much more efficient too. It is best to go with this.

It seems inside your situation you might want to cascade removes in song to version and removes in version to version info. Just stock up the table designer in SQL Manager and you ought to begin to see the relevant options under associations.

Should you place it properly within the database it should certainly cascade the removes. I believe they enhanced this within the next version from the Entity Framework but I'm not certain. I simply remember seeing cascade somewhere. I'd recommend you take a look within the database again.

For example, are there more relations that must also be cascaded?

within the RTM of EF, choose rapport within the designer, press F4 to determine qualities. you will see two OnDelete qualities (one for every side from the relationship) set to "none". you are able to set each side to "cascade" (I believe you need to place it around the parent)