0

Possible Duplicate:
How can i query for null values in entity framework?

I'm using entity framework to as my DAL. using the sql profiler i have intercepted the query to the database when i run the following line of code

 m_Context.DomainEntities.Where(e => e.EntityParentID == i_UnitID); 

When i_UnitID equals null, the query that its generates is:

exec sp_executesql N'SELECT 
[Extent1].[EntityTypeID] AS [EntityTypeID], 
[Extent1].[EntityID] AS [EntityID], 
[Extent1].[EntityName] AS [EntityName], 
[Extent1].[EntityParentID] AS [EntityParentID], 
...
FROM [dbo].[DomainEntities] AS [Extent1]
WHERE ([Extent1].[EntityTypeID] IN ( CAST( ''1'' AS int), CAST( ''2'' AS int), CAST( ''3'' AS int))) AND ([Extent1].[EntityParentID] = @p__linq__0)',N'@p__linq__0 int',@p__linq__0=NULL

Notice that it's using [Extent1].[EntityParentID] = @p__linq__0 in the where clause. that of course dosent work, i need it to generate the following

[Extent1].[EntityParentID] is NULL

is there a different method of using entity framework to achieve this ?

Community
  • 1
  • 1
Mortalus
  • 10,574
  • 11
  • 67
  • 117

1 Answers1

0

Try to write

m_Context.DomainEntities.Where(e => e.EntityParentID == Convert.ToInt32(i_UnitID));

and check the generated SQL query.

Boris Gappov
  • 2,483
  • 18
  • 23