1

I have multiple EDMX files in same project. All files targeting same database.

Table 'Customers' occurred two times but in different EDMX files.

Is there way to use classes with same names in different EDMX files?

My code:

using (var con = new TestEntities())
        {
            var q1 = con.ADDRESS.ToList();
            foreach (var item in q1)
            {
                Console.WriteLine(item.CITY);
            }
        }

        using (var con2 = new TestEntities1())
        {
            var q2 = con2.ADDRESS.ToList();
            foreach (var item in q2)
            {
                Console.WriteLine(item.CITY);
            }
        }

On second query "q2" I get error: The mapping of CLR type to EDM type is ambiguous because multiple CLR types match the EDM type.

First works normally.

Thanks

kat1330
  • 5,134
  • 7
  • 38
  • 61
  • 1
    Can you set a namespace on the .edmx properties, so code for that .edmx file is all within that namespace? Haven't used EF but you can in LINQ .dbml so I'd assume it's possible in EF. – James Gaunt Aug 12 '14 at 22:23
  • Namespace for first model is: HAS_Communicator_TESTModel, and for Second model is: HAS_Communicator_TESTModel1. I used different namespaces. – kat1330 Aug 12 '14 at 22:31
  • 1
    Ok, then perhaps you have a problem: http://stackoverflow.com/questions/14927391/the-mapping-of-clr-type-to-edm-type-is-ambiguous-with-ef-6-5, suggests you need to use distinct class names as the EF machinery uses just the class name not the FQN internally somewhere. No idea if this is still accurate however. Sorry! – James Gaunt Aug 12 '14 at 22:34
  • Yes I have that problem. I review this post but trying to found solution. For now I will forgot option with classes with same names. – kat1330 Aug 12 '14 at 22:45

1 Answers1

0

You need to specify the namespace for each of your models. Select the model in the solution explorer, right click and select properties. In the properties window change the Custom Tool Namespace for each model. For example if you have TestEntities.edmx and give it a Custom Tool Namespace of TestEntities, then your entities will be accessible under TestEntities.ADDRESS.

Repeat this for all models in your project so your TestEntities1.edmx file gets assigned to TestEntities1 and the ADDRESS objects will be accessible using TestEntities1.ADDRESS.

DavidG
  • 113,891
  • 12
  • 217
  • 223