简体   繁体   中英

Entity Framework - Multiple CLR Types

I am getting the following error when executing one one of my LINQ queries

The mapping of CLR type to EDM type is ambiguous because multiple CLR types match the EDM type 'Product'. Previously found CLR type 'TF.MyProject.DAL.Product, newly found CLR type 'TF.MyProject.DTO.Product'.

The Entity Framework generated class and the DTO object both are under their own namespace. This has worked previously and below is what I have tried so far...

  1. Regenerated the EDMX Model
  2. Removed and Created a new EDMX Model
  3. Run Custom Tool to generate the Template files
  4. Ensure all projects within the solution are using the same Entity Framework version.

Entity Framework version: 6.1.3

Below is how my current project is set up

MyProject

  • /DAL/MyProjectModel.edmx
  • /DTO/Product.cs

Any idea or suggestions will be helpful. This has worked in my previous projects with version 6. Not sure if it is specific to a version within release 6..

Note: Moving the DAL to a project of its own resolves the issue

You have two classes with the same name Product . Entity Framework uses Class Names only, irrespective of namespaces or files where it is declared. The error message clearly says you have two Product classes, one in TF.MyProject.DAL namespace and another one in TF.MyProject.DTO .

Try renaming on of these Product classes to some other name and try again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM