The entity set or function import 'name' is not defined in the entity container 'contextName'

c# entity-framework entity-framework-6

Question

I'm using Entity Framework 6.0 and Code First to migrate a legacy database schema to a new schema.

I'm getting an unexpected error upon querying EMPLOYEES:

The entity set or function import 'EMPLOYEES' is not defined in the entity container 'WebModel'. Near escaped identifier, line 1, column 14.

Here's the relevant parts of the context class.

public partial class WebModel : DbContext
{
    public WebModel : base("name=WebModel") { }

    public virtual DbSet<LEGACY_EMPLOYEE> EMPLOYEES { get; set; }

    public virtual DbSet<Employee> Employees { get; set; }
}

LEGACY_EMPLOYEE is a class that was generated by the built-in POCO generator from the legacy schema, and Employee is part of the new code first schema I've converting to.

In isolation, either one works. How do I fix this?

1
0
2/28/2017 1:10:26 AM

Popular Answer

The public virtual DbSet<LEGACY_EMPLOYEE> EMPLOYEES { get; set; } property can't have the same case insensitive name as another DbSet.

To clear this up, rename it to something else, like public virtual DbSet<LEGACY_EMPLOYEE> LEGACY_EMPLOYEES { get; set; }

0
2/28/2017 1:10:26 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow