2

I have two entity sets with entities of the same name with properties of the same name. Hence:

 FormsEntities formEntities2011 = new FormsEntities2011();
 FormsEntities formEntities2010 = new FormsEntities2010();

And I have queries for each:

 // -- Get a list of Clients from the 2010 Database for this agent
 var clients2010Query = from c in formsEntities2010.Clients
                        join ac in formsEntities2010.Agent_Client on c.Client_ID equals ac.Client_ID
                        where ac.Agent_ID == a.Agent_ID
                        orderby c.Client_ID
                        select c;

But I get an error on the join statement regarding ambiguity between Clients. I believe this is because the formEntities2011 and the formEntities2010 both have a Client entity.

Normally I would just add the namespace to resolve the ambiguity, but I don't know how to do that in a Linq statement?

The error is "The member is defined more than once" on c.Client_ID and ac.Client_ID

Matt Hudson
  • 7,329
  • 5
  • 49
  • 66
  • tvanfosson how did you format my code? Normally StackOverflow does it for me, but it didn't this time. – Matt Hudson Feb 02 '11 at 18:19
  • What is the exact error? Does the error change if you select out just one property of the client (say the Client_ID)? – tvanfosson Feb 02 '11 at 18:22
  • @Inturbidus -- you didn't have it indented far enough. It takes four spaces. – tvanfosson Feb 02 '11 at 18:22
  • Sorry! The error is "The member is defined more than once" on c.Client_ID and ac.Client_ID – Matt Hudson Feb 02 '11 at 18:22
  • If I change the select statement to select c.Client_ID it does not change the error. – Matt Hudson Feb 02 '11 at 18:24
  • Is it possible that your different entities map onto the same table? See: http://stackoverflow.com/questions/363026/linq-to-sql-this-member-is-defined-more-than-once-error – tvanfosson Feb 02 '11 at 18:26
  • Well I saw that answer. Each EDMX file is pointing to a completely different database. The databases have the same names and properties, but they aren't the same table. The part that confuses me is that you would think it would resolve to the entity set in the from part of the Linq statement. Also, the EDMXs have a Namespace setting, but I don't know where I would use it. – Matt Hudson Feb 02 '11 at 18:31
  • You might try using the extension methods instead of LINQ syntax, including the `Cast` method. That would let you specify the full type. – tvanfosson Feb 02 '11 at 18:37

2 Answers2

0

Change the namespaces on the entities to be different.

phattyD
  • 205
  • 3
  • 11
0

If you want to explicitly assign a type, try using extension methods and Cast.

var c2010 = formsEntities2010.Clients
                .Join( formsEntities1010.Agent_Client
                                        .Where( ac => ac.Agent_ID == a.Agent_ID ),
                       c => c.Client_ID,
                       ac => ac.Client_ID,
                       (c,ac) => c )
                .Cast<Forms2010.Client>(); // or whatever namespace you choose

I would be surprised, though, if this affected your problem since it seems to me that it is having difficulty determining which fields to use as the join keys.

tvanfosson
  • 524,688
  • 99
  • 697
  • 795