I haven't seen question like this been raised. So, I created one for EF fluent api developers and nopcommerce plugin developers.
Here's what I'm trying to do:
I have a product entity and can used by EF to generate database. I want to extending the product entity without modify original class. So, I've been try to use partial classes. here's the code look like:
namespace Nop.Core.Domain.Catalog
{
/// <summary>
/// Represents a product
/// </summary>
public partial class Product : BaseEntity, ILocalizedEntity, ISlugSupported, IAclSupported, IStoreMappingSupported
{
//some fields here.
public int ProductTypeId { get; set; }
//.....
}
}
Now when I extend the class like this:
namespace Nop.Core.Domain.Catalog
{
public partial class Product : BaseEntity
{
public int RestaurantId { get; set; }
public virtual Restaurant BelongRestaurant { get; set; }
}
}
It will throw an error.
The type 'Nop.Core.Domain.Catalog.Product' and the type 'Nop.Core.Domain.Catalog.Product' both have the same simple name of 'Product' and so cannot be used in the same model. All types in a given model must have unique simple names. Use 'NotMappedAttribute' or call Ignore in the Code First fluent API to explicitly exclude a property or type from the model.
Here is my mapping file look like:
namespace Nop.Plugin.Misc.Plugin
{
public partial class ProductMap : EntityTypeConfiguration<Nop.Core.Domain.Catalog.Product>
{
public ProductMap()
{
//Table
this.ToTable(Settings.DATABASE_TABLE_NAME);
//Primary Key
this.HasKey(t => t.Id);
//Property
this.Property(t => t.Id)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
this.HasRequired(p => p.BelongRestaurant)
.WithMany(r => r.Menu)
.HasForeignKey(p => p.RestaurantId)
.WillCascadeOnDelete(false);
}
}
}
Could anyone help?