Complex query that causes problem ?

I wote the following:

// One database that contains Users table I want to import to new database
FirstDb db1 = new FirstDb(connStr1);
// The destination database that is slightly different from the first.
SecondDb db2 = new SecondDb(connStr2)
...
var q = from e in db2.Users
           where e.GroupName == "Group1"
           from o in db1.Users
           where o.LoginID == e.UserID && o.CategoryID == ...

// Then I do some check against sequence q
if (q.Any())
...
// or
if (q.Count() > 0)
...

Always throws Exception(SqlException) telling me no such name in the database...



Answer this question

Complex query that causes problem ?

  • Tom Waters

    What happens when you use

    var q = 
          from e in db2.Users, o in db1.Users
          where e.GroupName == "Group1"
             && o.LoginID == e.UserID && ...



  • Kailash-Bisht

     Keith Farmer wrote:

    What happens when you use

    var q = 
          from e in db2.Users, o in db1.Users
          where e.GroupName == "Group1"
             && o.LoginID == e.UserID && ...



    It tells me there's no such "GroupName" in the table ! But I checked the spell carefully, and I'm sure all names were correct ( All the member names are auto-generated by sqlmetal, after all :) )

    I adjusted the two related tables relative position in the c# statement, this time the second table comes first, then run. This time it told me another field name in the table was not found!

  • Complex query that causes problem ?