如何解决以下MappingException [英] How to solve the following MappingException

查看:256
本文介绍了如何解决以下MappingException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到以下异常:



概念类型 MyModel.Customer中的成员数量
与对象侧的
成员数不匹配,键入
'MyNamespace.Customer'。确保
的成员数相同。

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.

在以下代码中:

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 */
    }
}

在我对EF模型进行一些更改之前,存储库工作正常。我让EF(通过从Model 选项生成数据库)创建数据库。

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).

我从哪里开始?

编辑:我已经解决了。

该问题与EF或我的模型无关。我已将数据层项目(及其程序集名称)从original_name.dll重命名为new_name.dll。我已经将服务层项目引用更新为数据层项目,但是旧程序集(original_name.dll)仍位于bin目录中。从服务层的bin目录中删除旧程序集并重建解决方案即可解决问题。

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.

推荐答案

似乎是类'MyModel。客户与 MyNamespace.Customer彼此不匹配。

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

尝试右键单击edmx文件并选择运行自定义工具

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

或在解决方案资源管理器中右键单击edmx并打开xml并验证您最近的更改。

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

这篇关于如何解决以下MappingException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆