InvalidOperationException: No field was found backing property 'NewsCategoriesMapping' of entity type 'NewsItem'. Lazy-loaded navigation properties must have backing fields. Either name the backing field so that it is picked up by convention or configure the backing field to use.
My classes :
1.MiscNewsItem
namespace Nop.Plugin.Misc.GetNewsItem.Manager.Domain
{
public partial class MiscNewsItem : BaseEntity, ISlugSupported, IStoreMappingSupported, ILocalizedEntity, IAclSupported
{
private ICollection<NewsItemComment> _newsComments;
private ICollection<NewsCategoryMapping> _newsCategories;
/// <summary>
/// Gets or sets the news title
/// </summary>
public string Title { get; set; }
/// <summary>
/// Gets or sets the short text
/// </summary>
public string ShortDescription { get; set; }
/// <summary>
/// Gets or sets the full text
/// </summary>
public string FullDescription { get; set; }
/// <summary>
/// Gets or sets the meta keywords
/// </summary>
public string MetaKeywords { get; set; }
/// <summary>
/// Gets or sets the meta description
/// </summary>
public string MetaDescription { get; set; }
/// <summary>
/// Gets or sets the meta title
/// </summary>
public string MetaTitle { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the news item is published
/// </summary>
public int PictureId { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the news post comments are allowed
/// </summary>
public bool AllowComments { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the entity is limited/restricted to certain stores
/// </summary>
public bool LimitedToStores { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the entity is subject to ACL
/// </summary>
public bool SubjectToAcl { get; set; }
public int TotalView { get; set; }
public string UserName { get; set; }
public string Email { get; set; }
/// <summary>
/// Gets or sets a value indicating whether to show the news item on home page
/// </summary>
public bool ShowOnHomePage { get; set; }
public bool ShowPictureDetail { get; set; }
public bool HasProductTag { get; set; }
public string ProductTags { get; set; }
public bool Published { get; set; }
public int DisplayOrder { get; set; }
public int TemplateId { get; set; }
/// <summary>
/// Gets or sets the news item start date and time
/// </summary>
public DateTime? StartDateUtc { get; set; }
/// <summary>
/// Gets or sets the news item end date and time
/// </summary>
public DateTime? EndDateUtc { get; set; }
/// <summary>
/// Gets or sets the date and time of entity creation
/// </summary>
public DateTime CreatedOn { get; set; }
/// <summary>
/// Gets or sets the date and time of news update
/// </summary>
public DateTime UpdatedOn { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the entity has been deleted
/// </summary>
public bool Deleted { get; set; }
/// <summary>
/// Gets or sets the news comments
/// </summary>
public virtual ICollection<NewsItemComment> NewsComments
{
get => _newsComments ?? (_newsComments = new List<NewsItemComment>());
protected set => _newsComments = value;
}
/// <summary>
/// Gets or sets the collection of NewsCategory
/// </summary>
public virtual ICollection<NewsCategoryMapping> NewsCategoriesMapping
{
get => _newsCategories ?? (_newsCategories = new List<NewsCategoryMapping>());
set => _newsCategories = value;
}
public virtual NewsItemTemplate Template { get; set; }
}
}
2.NewsCategoryMapping
namespace Nop.Plugin.Misc.GetNewsItem.Manager.Domain
{
public partial class NewsCategoryMapping : BaseEntity
{
public int NewsItemId { get; set; }
public int CategoryId { get; set; }
public int DisplayOrder { get; set; }
public virtual MiscNewsCategory NewsCategory { get; set; }
public virtual MiscNewsItem NewsItem { get; set; }
}
}
3.NewsCategoryMappingMap
namespace Nop.Plugin.Misc.GetNewsItem.Manager.Data
{
public partial class NewsCategoryMappingMap : NopEntityTypeConfiguration<NewsCategoryMapping>
{
public override void Configure(EntityTypeBuilder<NewsCategoryMapping> builder)
{
builder.ToTable(nameof(NewsCategoryMapping));
builder.HasKey(record => record.Id);
//NewsCategory
builder.HasOne(nc => nc.NewsCategory)
.WithMany()
.HasForeignKey(nc => nc.CategoryId).IsRequired();
//NewsItem
builder.HasOne(ni => ni.NewsItem)
.WithMany(nc => nc.NewsCategoriesMapping)
.HasForeignKey(ni => ni.NewsItemId).IsRequired();
//base.Configure(builder);
}
}
}
4.MiscNewsItemMap
namespace Nop.Plugin.Misc.GetNewsItem.Manager.Data
{
public partial class MiscNewsItemMap : NopEntityTypeConfiguration<MiscNewsItem>
{
public override void Configure(EntityTypeBuilder<MiscNewsItem> builder)
{
builder.ToTable(nameof(MiscNewsItem));
builder.HasKey(record => record.Id);
builder.Property(ni => ni.MetaKeywords).HasMaxLength(400);
builder.Property(ni => ni.MetaTitle).HasMaxLength(400);
builder.HasOne(nc => nc.Template)
.WithMany(n => n.NewsItems)
.HasForeignKey(nc => nc.TemplateId);
//base.Configure(builder);
}
}
}
Please help me!!!