First of all and as you can see in the title, I'm designing a plugin for nopCommerce. I believe that the problem is not related to it (but with Entity Framework) but I'm not really sure.
My plugin has access to data, and nopCommerce let's me create my own context, creating the required tables and relations.
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new ParentMap());
modelBuilder.Configurations.Add(new ChildMap());
}
Conceptually, what I would like to have is:
ROOT TABLE ----(1:N)---- CHILDTABLE ----(1:1)---- EXISTING NOPCOMMERCE TABLE
And the tables and columns created in the DB seems correct to me. The mappings are pretty simple:
public ParentMap()
{
ToTable("TableA");
HasKey(m => m.Id);
Property(m => m.SomeProperty);
HasMany(m => m.Child).WithRequired(s => s.Parent).WillCascadeOnDelete();
}
public ChildMap()
{
ToTable("TableB");
HasKey(m => new { m.Id });
HasRequired(m => m.NopCommerceEntity);
HasRequired(m => m.Parent);
}
Till this point, everything seems to work pretty well, things get registered and the application starts. When I try to insert or update anything that has relation with the nopCommerce entity, I get the following exception:
"The member with identity 'Namespace.ChildObject_NopCommerceEntity' does not exist in the metadata collection.\r\nParameter name: identity".
I've been thinking that the problem could be related with the fact that I'm not adding other mappings in my OnModelCreating. I've tried to add all the related mappings there but I get the same exception.
It's a bit complicated. I'd be very greatful for your help & time :)