How do you address the following problems? MappingException

c# entity-framework

Question

I'm getting the following exception:

The number of members in the conceptual type 'MyModel.Customer' does not match with the number of members on the object side type 'MyNamespace.Customer'. Make sure the number of members are the same.

In the following code:

public CusomserService
{
    // ...

    public IEnumerable<Customer> GetCustomers()
    {
        return new Repository<Customer>().All(); 
    }
}

public class Repository<T>() where T : EntityObject
{
    // ...

    public IQueryable<T> All()
    {
        return _context.CreateObjectSet<T>().AsQueryable<T>(); /* HERE THE EXCEPTION IS THROWN */
    }
}

The generics repository was working fine until I made some changes in my EF Model. I'm letting EF create the database (through Generate database from Model option).

Where do I start?


EDIT: I've solved it.

The problem had nothing to do with EF or my model. I had renamed the data layer project (and it's assembly name) from original_name.dll to new_name.dll. I had updated the service layer project reference to the data layer project, but the the old assembly (original_name.dll) was still in the bin directory. Deleting the old assembly from the service layer's bin directory and rebuilding the solution solved the problem.

1
6
3/30/2011 1:31:56 PM

Popular Answer

It seems that Classes 'MyModel.Customer' does not match with each other 'MyNamespace.Customer'.

Try right clicking on the edmx file and selecting Run Custom Tool

or right click on edmx in solution explorer and open with xml and verify your recent changes.

9
3/30/2011 12:56:43 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