The EntityContainer name must be unique. An EntityContainer with the name 'Entities' is already defined

前端 未结 12 1014
孤城傲影
孤城傲影 2020-12-15 03:11

For a little background:

I have a DLL project with the following structure:

Rivworks.Model (project)  
  \\Negotiation (folder)  
      Model.edmx          


        
12条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-15 03:42

    I just ran into this. It looks like somehow Entity Framework got into a bad state in terms of what tables it thought it needed to add.

    Normally EF will not recognize that a new table has to be created until you put the line

    public virtual DbSet NewTable { get; set; }
    

    inside your context class.

    However, EF somehow got into a bad state where the mere presence of the NewTable class in my solution was triggering it to think that it needed to generate that table. So by the time the above line in the context triggered it to create a NewTable table, it already thought it had done it, hence the error about duplicate entities.

    I just removed the NewTable class from my solution, commented things out so it would compile again (thankfully there wasn't too much of this), then added a new migration to make sure it was blank as it should have been. Then once things were back into a more predictable state, I re-added the NewTable class back into the solution and adding the migration worked fine.

提交回复
热议问题