I've created a many to many relationship using default conventions in EF CTP4 by defining an ICollection on both image and project entities.
The mapping table is created as below:
create table [dbo].[Images_Project] (
[Images_Id] [uniqueidentifier] not null,
[Project_Id] [uniqueidentifier] not null,
primary key ([Images_Id]));
Unfortunately when I delete a project it is not cascading deletes to the image mapping table.
I would expect EF to generate a key on both the Imanges_Id and Project_Id properties but this is not the case. How can I configure EF to delete the image mappings when a project is deleted? (only the image mapping record, not the image record)
Thanks
[Update]
Although cascade is apparently not possible, any idea why the following test passes:
[Test]
public void Can_delete_project_with_images()
{
var project = new Project { Title = "Test project" };
var image = new Image { Title = "Some image" };
project.AddImage(image);
context.Set<Project>().Add(project);
context.SaveChanges();
object id = project.Id;
object imageId = image.Id;
var fromDb = context.Projects.Find(id);
fromDb.ShouldNotBeNull();
context.Set<Project>().Remove(fromDb);
context.SaveChanges();
var fromDb2 = context.Images.Find(imageId);
fromDb2.ShouldNotBeNull();
fromDb2.Title.ShouldEqual("Some image");
}