Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve the following MappingException

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.

like image 614
mmutilva Avatar asked Mar 30 '11 00:03

mmutilva


1 Answers

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.

like image 156
swapneel Avatar answered Sep 23 '22 07:09

swapneel