Join RRS feed

  • Question

  • Hi,
       I have parent table 'Parent'  like the below:
    Parent_Id, name, Child_Id
    and child table 'Child' with columns: Child_Id, name.

    Parent table has the following data:
    Parent_Id   |    Name |   Child_Id
       1            |    x        |   null

    When I write the query to find whether the child exists by giving parent id like the below:

    var exist = (from p in ctx.Parents
                      where p.Parent_Id == 1
                      select p.Child).count > 0;

    in the above data, child is null but the above linq query returning me true, when I execute the translated Sqlserver query from the above linq query it is returning one row with all null data it may due to parent row exists? Is this correct behaviour? How to get false in exist variable when child is not there?

    Thanks in advance
    Friday, January 1, 2010 12:36 AM


All replies