Wiki Link: [discussion:854]
Bug with code generated from edmx 

Oct 27 2008 at 1:40 AM
Edited Oct 27 2008 at 2:26 AM
When creating entities with the Entity Data Model tool, the EFPocoContext.cs throws an exception in the EFPocoContext.cs file after calling InsertOnSaveChanges:

"An EdmType cannot be mapped to CLR classes multiple times. The EdmType 'PocoAdapterNamespace.EntityName' is mapped more than once."

Please Note that the EntityName in the edmx is the same name as the POCO Class, (namespaces are different).

This is occuring in the GetEntitySet<T>(string name) method in the following line:

ObjectQuery oq = (ObjectQuery)createQueryOfT.Invoke(PersistenceAwareContext, new object[] { name, new ObjectParameter0 });

When I delete the generated EntityName class in the edmx file all is good.

Dec 13 2008 at 12:40 AM
Hi,

What part has to be deleted, I'm confused.

thanks

Martin

Jan 2 2009 at 11:04 PM
Edited Jan 2 2009 at 11:22 PM
I'm experiencing a similar bug. Here's some steps to recreate the issue:

1. Create a new project with an ADO.NET Entity Data Model (.edmx) for the NorthwindEF database.
2. Generate the POCO classes using EFPocoClassGen.exe.
3. Generate the POCO Adapter classes using EFPocoClassGen.exe.
4. Generate the POCO Container classes using EFPocoClassGen.exe.
5. Create a console application that write the CustomerName from the Customer object to the console.

Here's the exception that I receive:

System.Reflection.TargetInvocationException was unhandled
Message="Exception has been thrown by the target of an invocation."
Source="mscorlib"
StackTrace:
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at EFPocoAdapter.EFPocoContext.GetEntitySetT(String name) in C:\LDSProjects\GPD\EFPocoAdapter\EFPocoContext.cs:line 138
at GPD.Data.GPMEntityDataContext.get_PropGenerals() in C:\LDSProjects\GPD\GPD.Data\PocoContext\GPMEntityDataContext.cs:line 23
at GPD.ConsoleTest.Program.Main(String[] args) in C:\LDSProjects\GPD\GPD.ConsoleTest\Program.cs:line 20
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.ArgumentException
Message="An item with the same key has already been added."
Source="mscorlib"
StackTrace:
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Data.Metadata.Edm.ObjectItemCollection.AssemblyCacheEntry.LoadRelationshipTypes(LoadingContext context)
at System.Data.Metadata.Edm.ObjectItemCollection.AssemblyCacheEntry.LoadTypesFromAssembly(LoadingContext context)
at System.Data.Metadata.Edm.ObjectItemCollection.AssemblyCacheEntry.InternalLoadAssemblyFromCache(LoadingContext context)
at System.Data.Metadata.Edm.ObjectItemCollection.AssemblyCacheEntry.LoadAssemblyFromCache(Assembly assembly, Boolean loadReferencedAssemblies, Dictionary`2 knownAssemblies, Dictionary`2& typesInLoading, List`1& errors)
at System.Data.Metadata.Edm.ObjectItemCollection.LoadAssemblyFromCache(ObjectItemCollection objectItemCollection, Assembly assembly, Boolean loadReferencedAssemblies)
at System.Data.Metadata.Edm.ObjectItemCollection.LoadAssemblyForType(Type type)
at System.Data.Metadata.Edm.MetadataWorkspace.LoadAssemblyForType(Type type, Assembly callingAssembly)
at System.Data.Objects.ObjectContext.CreateQueryT(String queryString, ObjectParameter[] parameters)
InnerException:

The easiest way to fix this issue is to remove the Designer.cs file associated with the .edmx file.

Coordinator
Mar 12 2009 at 6:04 AM
Removing the designer.cs file is the right way to fix the problem. Having two classes, EF cannot properly determine which one to map to.


Updating...
Page view tracker