Please any one can help me to fix this error?
Schema specified is not valid. Errors:
The mapping of CLR type to EDM type is ambiguous because mult
This MSDN forum question might be helpful. It suggest placing the BLL and DAL classes in separate assemblies.
For EF 6.x, I found some notes at https://github.com/aspnet/EntityFramework/issues/941 and fixed this in my solution by adding annotation to the EDM type.
I edited the EDMX file manually and changed a line like this:
<EntityType Name="CartItem">
to this:
<EntityType Name="CartItem" customannotation:ClrType="EntityModel.CartItem">
or use this if you have existing type elsewhere:
<EntityType Name="CartItem" customannotation:ClrType="MyApp.CartItem, MyApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
where EntityModel is the namespace used for my EF model, and MyApp is the namespace of a business object
This may not have been available when the question was asked, but another solution is to delete the EDMX and recreate it as a code-first entity data model. In EF6, with code-first, you can map two classes with the same name from different model namespaces without creating a conflict.
To create the entity data model in Visual Studio (2013), go to "Add" > "New Item..." > "ADO.NET Entity Data Model". Be sure to choose the "Code First from database" option.
Don't use classes with the same unqualified name - EF uses only class names to identify the type mapped in EDMX (namespaces are ignored) - it is a convention to allow mapping classes from different namespaces to single model. The solution for your problem is to name your classes in BLL differently.
Workaround: Change a property on one of the two identical classes.
EF matches on class name AND class properties. So I just changed a property name on one of the EF objects, and the error is gone.
As @Entrodus commented on one of the other answers:
EF collision happens only when two classes have the same name AND the same set of parameters.
Another reason you might get this error: If you're loading custom assemblies with Assembly.LoadFile that have edmx files, that have already been loaded into memory. This creates duplicate classes that entity framework doesn't like.