Unable to determine the principal end of an association between the types 'Nop.Core.Domain.Orders.Order' and 'Nop.Core.Domain.Customers.RewardPointsHistory'. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations.
My models are as follows:
public class MyProduct : BaseEntity
{
public int CustomerId { get; set; }
public Customer Customer { get; set; }
public int ProductId { get; set; }
public string ProductName { get; set; }
public int NotesCount { get; set; }
public virtual ICollection<MyProductNote> Items { get; set; }
public MyProduct()
{
Items = new HashSet<MyProductNote>();
}
}
public class MyProductNote : BaseEntity
{
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public string Note { get; set; }
public int MyProductId { get; set; }
public virtual MyProduct MyProduct { get; set; }
public string FullName
{
get
{
return FirstName + (string.IsNullOrWhiteSpace(MiddleName) ? "" : (" " + MiddleName)) + " " + LastName;
}
}
}
The mapping EntityTypeConfiguration classes are:
public class MyProductMap : EntityTypeConfiguration<MyProduct>
{
public MyProductMap()
{
ToTable("LTMyProduct");
HasKey(x => x.Id);
Property(x => x.CustomerId).IsRequired();
Property(x => x.ProductId).IsRequired();
Property(x => x.ProductName).IsUnicode().IsVariableLength().HasMaxLength(250).IsOptional();
HasMany(x => x.Items);
}
}
public class MyProductNoteMap : EntityTypeConfiguration<MyProductNote>
{
public MyProductNoteMap()
{
ToTable("LTMyProductNote");
HasKey(x => x.Id);
Property(x => x.FirstName).HasMaxLength(50).IsRequired().IsUnicode().IsVariableLength();
Property(x => x.MiddleName).HasMaxLength(50).IsUnicode().IsVariableLength();
Property(x => x.LastName).HasMaxLength(50).IsRequired().IsUnicode().IsVariableLength();
Property(x => x.Note).IsVariableLength().HasMaxLength(1024).IsUnicode();
Property(x => x.MyProductId).IsRequired().HasColumnType("int");
}
}
When DataContext class's OnModelCreating method is called:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new MyProductMap());
modelBuilder.Configurations.Add(new MyProductNoteMap());
base.OnModelCreating(modelBuilder);
}
The line base.OnModelCreating(modelBuilder); is causing the issue.
It gives aforementioned exception. Note that I am not referring to any NopCommerce base class except the BaseEntity.