I'm having difficulties extending with plugin default nopCommerce 3.7. entities like Country, Customer while extended Picture works fine.
I've tried different solutions and none of them were applicable to be used in plugin without touching source code. I have existing nopCommerce database (upgraded from nop 1.9 to 3.7) with several custom tables. So I need to implement all of them, including additional properties defining one-to-many, many-to-many and even one-to-one relations.
How I extend Picture:
1) created additional column on Picture table
2) inherited PictureExt from default Picture
public partial class PictureExt : Picture
{
/// <summary>
/// Gets or sets the ExternalUrl
/// </summary>
public virtual string ExternalUrl { get; set; }
}
3) fully copied PictureMap constructor to my PictureExtMap constructor
public class PictureMap : NopEntityTypeConfiguration<PictureExt>
{
public PictureMap()
{
this.ToTable("Picture");
this.HasKey(p => p.Id);
this.Property(p => p.PictureBinary).IsMaxLength();
this.Property(p => p.MimeType).IsRequired().HasMaxLength(40);
this.Property(p => p.SeoFilename).HasMaxLength(300);
this.Property(p => p.ExternalUrl).IsOptional();
}
}
And it works. I can access PictureExt objects, and the field ExternalUrl will contain value.
This steps also worked for MyCustomCurrency extended from Currency.
Then I did the same for Country. I just need extended entity to implement some different relations later.
1) inherited Country
public partial class MyCustomCountry : Country
{
}
2) fully copied CountryMap constructor to my MyCustomCountryExtMap constructor
public partial class MyCustomCountryMap : NopEntityTypeConfiguration<MyCustomCountry>
{
public MyCustomCountryMap()
{
this.ToTable("Country");
this.HasKey(c => c.Id);
this.Property(c => c.Name).IsRequired().HasMaxLength(100);
this.Property(c => c.TwoLetterIsoCode).HasMaxLength(2);
this.Property(c => c.ThreeLetterIsoCode).HasMaxLength(3);
}
}
And it's not working... It shows an error: "Invalid column name 'Discriminator'".
Can someone will what is the major difference in this 2 examples? Why can I inherit Picture and Currency and can't inherit country and customer? And how i extend Country and Customer classes from a plugin?