I want to create table with two properties with relations to same table, one-to-one. My model:
public class ImageFile : BaseEntity
{
[Key]
Guid Guid { get; set; }
public string Name { get; set; }
public string Extension { get; set; }
public long Size { get; set; }
public byte[] FileContent { get; set; }
public ProjectImage ProjectImage { get; set; }
}
public class ProjectImage : BaseEntity
{
public string Description { get; set }
public ImageFile Thumbnail { get; set; }
public ImageFile FullSizeImage { get; set; }
}
Here is the part of my context:
modelBuilder.Entity<ProjectImage>()
.HasRequired(f => f.FullSizeImage)
.WithOptional(i => i.ProjectImage);
modelBuilder.Entity<ProjectImage>()
.HasRequired(f => f.Thumbnail)
.WithOptional(i => i.ProjectImage);
It create database one-to-many. Why?
EDIT V2:
public class ImageFile : BaseEntity
{
[Key]
Guid Guid { get; set; }
public string Name { get; set; }
public string Extension { get; set; }
public long Size { get; set; }
public byte[] FileContent { get; set; }
public Guid? ProjectImageGuid { get; set; }
[ForeignKey("ProjectImageGuid")]
public ProjectImage ProjectImage { get; set; }
}
public class ProjectImage : BaseEntity
{
public string Description { get; set }
public Guid? ThumbnailGuid { get; set; }
public Guid? FullSizeImageGuid { get; set; }
[ForeignKey("ThumbnailGuid")]
public ImageFile Thumbnail { get; set; }
[ForeignKey("FullSizeImageGuid")]
public ImageFile FullSizeImage { get; set; }
}
Here is the part of my context:
modelBuilder.Entity<ProjectImage>()
.HasRequired(f => f.FullSizeImage)
.WithOptional(i => i.ProjectImage);
modelBuilder.Entity<ProjectImage>()
.HasRequired(f => f.Thumbnail)
.WithOptional(i => i.ProjectImage);
I have error:
ProjectImage_Thumbnail_Source: : Multiplicity is not valid in Role 'ProjectImage_Thumbnail_Source' in relationship 'ProjectImage_Thumbnail'. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be '*'.