0

I am having a difficulty when doing the automatic migration. Here is the case:

I have 2 contexts, one is EAccounting context and one is ECommerce context. EAccounting context has:

public DbSet<EA_Item> Items { get; set; }

And there is entity inside the ECommerce context which dependent to EA_Item

This is the entity in ECommerce that has EA_Item dependency in it:

public DbSet<EC_Product> Products { get; set; }

And this is the EC_Product:

[Table("EC_Product", Schema = "dbo")]
[Serializable]
public class EC_Product
{
    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    [Display(Name = "Product Id")]
    public int ProductId { get; set; }

    [Display(Name = "Item Id")]
    [Required]
    public int ItemId { get; set; }

    [Display(Name = "Published")]
    public bool Published { get; set; }

    [Display(Name = "Category")]
    public int? CategoryId { get; set; }

    [Display(Name = "Is Featured")]
    public bool IsFeatured { get; set; }

    [ForeignKey("ItemId")]
    public virtual EAccounting.Models.EA_Item Item { get; set; }

    [ForeignKey("CategoryId")]
    public virtual ECommerce.Models.EC_Category Category { get; set; }

    public EC_Product()
    {
        ItemId = 0;
        CategoryId = null;
        IsFeatured = false;
    }
}

It has EA_Item whenever I run the program it gives me:

entity framework migration There is already an object named "EA_Item" in the database.

EAccounting and ECommerce assemblies are not in one, they are seperated. EAccounting does not know there is ECommerce assembly, but ECommerce assembly requires EAccounting assembly to be loaded.

Is it possible to do this?

Alvin Stefanus
  • 1,873
  • 2
  • 22
  • 60
  • 1
    What are you going to solve with the two contexts? Raising pain? – Sir Rufo Apr 18 '17 at 08:56
  • I am implementing plugin system with MEF that is why plugin EAccounting can stand alone but plugin ECommerce requires EAccounting to be installed first – Alvin Stefanus Apr 18 '17 at 09:11
  • I think this is what you are trying to accomplish: http://stackoverflow.com/questions/11197754/entity-framework-one-database-multiple-dbcontexts-is-this-a-bad-idea – Jim Crandall Apr 18 '17 at 18:49

0 Answers0