Home > Software engineering >  What is this last part when i display my generated SQL from query in c#? And can i remove it?
What is this last part when i display my generated SQL from query in c#? And can i remove it?

Time:12-06

When i generate my Query from C# it shows this

SELECT [Extent1].[Id] AS [Id], [Extent1].[RegionName] AS [RegionName] 
FROM [dbo].[RegionClasses] AS [Extent1] 
WHERE ([Extent1].[RegionName] = @p__linq__0) 
  OR (([Extent1].[RegionName] IS NULL) AND (@p__linq__0 IS NULL))

But the problem is where last "OR" is. Why is it there and how do i remove it? what does it do?

below is my code for the query from C#:

var RegionlinqQuery = from regions
                      in ctx.Regions
                      where regions.RegionName == SearchTextBox.Text
                      select regions;

string sqlQuery = RegionlinqQuery.ToString();
RegionLabel.Text = sqlQuery;

CodePudding user response:

You need to enable the context.Configuration.UseDatabaseNullSemantics to disable this behavior. You can check the documentation here

  • Related