I have an entity that includes many different documents with unkown-relations to any entities in my database.
public class Document : BaseEntity
{
public string Filename { get; set; }
public string MIMEType { get; set; }
public int? Length { get; set; }
public byte[] Content { get; set; }
}
and the codefirst-mapping is:
public DocumentConfiguration()
{
Property(x => x.Filename).HasMaxLength(300).IsRequired();
Property(x => x.MIMEType).HasMaxLength(300).IsRequired();
Property(x => x.Length).IsOptional();
Property(x => x.Content).IsOptional().HasColumnType("varbinary(max)");
ToTable("Document");
}
Now I want an optional relation to document-table in my addressentity like so:
public class Address : BaseEntity
{
public string Name1 { get; set; }
public string Name2 { get; set; }
public string Additional { get; set; }
public string Street { get; set; }
public string HousNr { get; set; }
public string ZipCode { get; set; }
public string City { get; set; }
public virtual Document Image { get; set; }
}
with the following mapping:
public AddressConfiguration()
{
Property(x => x.Name1).IsRequired().HasMaxLength(250);
Property(x => x.Name2).HasMaxLength(250);
Property(x => x.Additional).HasMaxLength(250);
Property(x => x.Street).HasMaxLength(250);
Property(x => x.HousNr).HasMaxLength(10);
Property(x => x.ZipCode).HasMaxLength(10);
Property(x => x.City).HasMaxLength(100);
HasOptional(x => x.Image)
.WithOptionalDependent()
.Map(map => map.MapKey("ImageId")).WillCascadeOnDelete();
ToTable("Address");
}
But it deletes the related address when I delete an image in the document-table.
I would like a OneWay-Deletation from address to document, but not from document to address...?
How can i implement that?
thank you.