Question: Whats wrong with following code? :(

```
int? parentFolderId = null;
if( this.Request.QueryString ["folderId"] != null )
    parentFolderId = Convert.ToInt32( this.Request.QueryString ["folderId"] );
f = ( from x in this.EntityDataContext.folders
        where x.parent_id == parentFolderId
        select x ).ToList();

```

It returns nothing! Though there ARE records in database with parent\_id as NULL.

However, when I explicitly state NULL; it works!

```
f = ( from x in this.EntityDataContext.folders
        where x.parent_id == null
        select x ).ToList();

```

What could be the issue?

PS: I hate working with mysql using Entity Framework .... every damn simple thing has million issues!

Answer: 
I had this kind of problem in sql server and in sql server the generated query looks like "parent\_id = null" when you are working on a nullable field. And that query returns nothing even parent\_id is null.

The tricky way in here is, you should force EF to create a query like "parent\_id is null" and the code I tried in linq was;

```
if(parentFolderId.HasValue)
{
    f = ( from x in this.EntityDataContext.folders
                where x.parent_id == parentFolderId
                select x ).ToList();
}
else
{
    f = ( from x in this.EntityDataContext.folders
                where !x.parent_id.HasValue
                select x ).ToList();
}

```

I know this does not seem a perfect way to do this but, this is how I could get rid of that issue.
You'll probably find there's an issue involving using DBNull or something similar. I would think that in the second case (where you explicitly state "null") that Linq is automatically transforming it to DBNull in the background.

perhaps try something along the lines of:

```
where x.parent_id == ( parentFolderId == null ? DBNull.Value : parentFolderId )

```

Hope that puts you on the right track!