Entity Relationship Error : UseLazyLoadingProxies requires all entity types to be public, unsealed, have virtual navigation properties, and have a pub

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
4 years ago
Hi All,
I trying to add an existing product id as a foreign key in my Entity.
I have created DiscountType class and added a property for products
public class DiscountType : BaseEntity 
    {
        public string TypeCode { get; set; }
        public string TypeName { get; set; }
    //Product is existing class of nop commerce
   public Product product { get; set; }
    }


Created DiscountTypeMap class and added relation between both tables
 public class DiscountTypeMap : NopEntityTypeConfiguration<DiscountType>
    {
       public override void Configure(EntityTypeBuilder<DiscountType > builder)
        {
            builder.ToTable(nameof(DiscountType ));
            builder.HasKey(point => point.Id);
            builder.HasOne<Product>(s => s.Product);
        }
}

When running the plugin I am getting the following error

"Navigation property 'Addresses' on entity type 'Customer' is not virtual. UseLazyLoadingProxies requires all entity types to be public, unsealed, have virtual navigation properties, and have a public or protected constructor."

I am not sure why this error is coming.  Please share if I missed anything.

Thank You in advance.
4 years ago
Try making the Product property virtual in your DiscountType  class and see if it works
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.