question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The mapping of CLR type to EDM type is ambiguous because multiple CLR types match the EDM type

See original GitHub issue

Schema specified is not valid. Errors: The mapping of CLR type to EDM type is ambiguous because multiple CLR types match the EDM type 'Crop'. Previously found CLR type 'AFI.Core.DataModels.gen2.Crop', newly found CLR type 'AFI.Core.DataModels.gen3.Crop'.

I get this exception at runtime when querying entities from a database via LINQ. In my project I use Database First and I have two classes with the same name but different namespaces. Each class belongs to a separate model and each model has its own connection string and thus own database.

This bug is at least two years old. The orginal bug has been posted by mousedoc here: http://entityframework.codeplex.com/workitem/483

Are there any plans on fixing this bug in the nearest future?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
divegacommented, Feb 5, 2016

@davimack This repo is for EF Core, so the issue was closed because there is nothing actionable that applies to EF Core. The bug remains open in the EF6 repo at http://entityframework.codeplex.com/workitem/483.

BTW, in one of the minor releases of EF6.x we added annotations that can be put in entity types in the EDMX to identify the CLR type they will be mapped to at runtime deterministically, which avoids scanning assemblies for all possible candidate CLR types and avoids the exception.

The EDMX needs to be edited manually to add the annotations since the tools won’t add them. For a simple model with a Person entity, the ConceptualModels section of the EDMX would look like this:

<ConceptualModels>
    <Schema Namespace="ConsoleApplication33" 
        Alias="Self" 
        annotation:UseStrongSpatialTypes="false"
        xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" 
        xmlns:customannotation="http://schemas.microsoft.com/ado/2013/11/edm/customannotation" 
        xmlns="http://schemas.microsoft.com/ado/2009/11/edm">
    <EntityType Name="Person" 
        customannotation:ClrType="MyApp.Person, MyApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
        <Key>
        <PropertyRef Name="Id" />
        </Key>
        <Property Name="Id" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
        <Property Name="Name" Type="String" MaxLength="Max" FixedLength="false" Unicode="true" />
    </EntityType>
    <EntityContainer Name="Town" customannotation:UseClrTypes="true">
        <EntitySet Name="People" EntityType="Self.Person" />
    </EntityContainer>
    </Schema>
</ConceptualModels>

Notice in particular the customannotation:ClrType on the Person entity type and the customannotation:UseClrTypes on the entity container.

0reactions
krptodrcommented, Jun 21, 2018

How would you go about doing this with ComplexTypes?

Read more comments on GitHub >

github_iconTop Results From Across the Web

The mapping of CLR type to EDM type is ambiguous with ...
The mapping of CLR type to EDM type is ambiguous because multiple CLR types match the EDM type 'City_DAL'. Previously found CLR type...
Read more >
The mapping of CLR type to EDM type is ambiguous
The mapping of CLR type to EDM type is ambiguous because multiple CLR types match the EDM type 'CmnAddressCity'. Previously found CLR type...
Read more >
The most ridiculous thing ever in Entity Framework : r/dotnet
Schema specified is not valid. Errors: The mapping of CLR type to EDM type is ambiguous because multiple CLR types match the EDM...
Read more >
The mapping of CLR type to EDM is ambiguous
This happens because of EntityFramework While CSDL (Conceptual schema definition language , instance of the System.Data.
Read more >
The mapping of CLR type to EDM type is ambiguous
The mapping of CLR type to EDM type is ambiguous because multiple CLR types match the EDM type 'CmnAddressCity'. Previously found CLR type...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found