加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何解决以下MappingException

发布时间:2020-12-15 08:25:25 所属栏目:百科 来源:网络整理
导读:我收到以下异常: 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. 在以下代码中: pub
我收到以下异常:

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创建数据库(通过从模型选项生成数据库).

我从哪里开始?

编辑:我已经解决了.

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

解决方法

似乎Classes的’MyModel.Customer’彼此不匹配’MyNamespace.Customer’.

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读