Why does the first line after calling base in OnModelCreating cause an error? The commented line that throws causes this error:
The expression 'x => value(Blog.Services.Db).ContentItems' is not a valid property expression. The expression should represent a property access: 't => t.MyProperty'. Parameter name: propertyAccessExpression
protected override void OnModelCreating(ModelBuilder mb)
{
base.OnModelCreating(mb);
mb.Entity<ContentGroup>().HasMany(x => ContentItems).WithOne(x => x.ContentGroup).HasForeignKey(x => x.ContentGroupID); // same effect as following line but throws an error
//mb.Entity<ContentItem>().HasOne(x => x.ContentGroup).WithMany(x => x.ContentItems).HasForeignKey(x => x.ContentGroupID); // same effect as previous line but works
}
ContentGroup:
public class ContentGroup
{
public int ID { get; set; }
public int SiteID { get; set; }
public string Description { get; set; }
public int Sequence { get; set; }
public bool Active { get; set; }
public virtual Site Site { get; set; }
public virtual ICollection<ContentItem> ContentItems { get; set; }
}
ContentItem:
public class ContentItem
{
public int ID { get; set; }
public string ContentType { get; set; }
public int ContentGroupID { get; set; }
public DateTime? PublishDate { get; set; }
public DateTime? LastModifyDate { get; set; }
public string ChangeFrequency { get; set; }
public decimal? Priority { get; set; }
public bool Active { get; set; }
public string Slug { get; set; }
public string Title { get; set; }
public string MenuText { get; set; }
public string URI { get; set; }
public string Abstract { get; set; }
public string Icon { get; set; }
public string Tags { get; set; }
public bool AllowComments { get; set; }
public virtual ICollection<Comment> Comments { get; set; }
public virtual ContentGroup ContentGroup { get; set; }
public virtual ICollection<MenuContentItem> MenuContentItems { get; set; }
}
