I am using Entity Framework 4.1 (code first) and have defined entities similar to the following
public class ImageItem
{
[Column(IsDbGenerated = true, IsPrimaryKey = true, AutoSync = AutoSync.OnInsert)]
public int Id { get; set; }
public string ImageUrl { get; set; }
public int Height { get; set; }
public int Width { get; set; }
// other stuff in here
}
public class MyItemWithImages
{
[Column(IsDbGenerated = true, IsPrimaryKey = true, AutoSync = AutoSync.OnInsert)]
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<ImageItem> Thumbnails { get; set; }
// other stuff in here
}
What I am trying to achieve is to add another property to hold a “MainImage” item of type ImageItem, that does not necessarily appear in the thumbnails collection.
I have tried adding the following
public virtual ImageItem MainImage { get; set; }
but this overrides the relationship between the MyItemWithImages.Thumbnails collection – not what I would like to happen.
Can anyone point me in the right direction to add this new property, please?
You will need to use the fluent mappings to map your model.
Override the
OnModelCreatingmethod of your customDbContextIf you have included the Foreign Key columns as properties then use those in the mappings.
Go through the Fluent Mapping API for more details about mappings.