I am currently working with ASP.NET core.
I have a BaseModel
and SubModel
which is structured like this:
class BaseClass{
SubClass MainSubClass {get;set;}
List<SubClass> SubClasses {get;set;}
}
When I try to add migrations with this, I get this error:
Unable to determine the relationship represented by navigation property 'StoreModel.StoreMainPhoto' of type 'StorePhotoModel'. Either manually configure the relationship, or ignore this property from the model.`*
The real data models are...
in StoreModel.cs
[Table("Stores")]
public class StoreModel
{
[Key]
public int Id { get; set; }
[Required]
[MaxLength(25)]
public string StoreName { get; set; }
[MaxLength(80)]
public string StoreShortDescription { get; set; }
[MaxLength(4000)]
public string StoreFullDescription { get; set; }
public string StoreLocation { get; set; }
public string StoreAddress { get; set; }
#region graphics Data
public StorePhotoModel StoreMainPhoto { get; set; }
public ICollection<StorePhotoModel> StorePhotos { get; set; }
#endregion
public ICollection<MenuModel> Menus { get; set; }
public ICollection<StoreReviewModel> StoreReviews { get; set; }
#region store contacts
public string StorePhoneNumber { get; set; }
public string StoreExtraContacts { get; set; }
#endregion
public StoreModel()
{
StorePhotos = new Collection<StorePhotoModel>();
Menus = new Collection<MenuModel>();
StoreReviews = new Collection<StoreReviewModel>();
}
}
in StorePhotoModel.cs
[Table("StorePhotos")]
public class StorePhotoModel : MediaModel
{
// base Store
public int BaseStoreId { get; set; }
[ForeignKey(nameof(BaseStoreId))]
public StoreModel BaseStore { get; set; }
}