Using "Is NULL / not NULL" in LINQ To SQL

I would like to translate this query in LINQ to SQL:

SELECT * from Agir where NouvelIncident='1' AND facturable is null 

My attempt:

  public static List<Agir> GetINDEFAgir() { DataClassesActilogDataContext db = ContextSingleton.GetDataContext(); List<Agir> list; var v = from i in db.Agir where i.facturable is null && i.NouvelIncident == true select i; list = v.ToList(); return list; } 

It seems that "null" is not allowed in LINQ to SQL ... I have an error.

Thank you in advance for your help.

+6
source share
2 answers

Use == , 'is' for type checking

 public static List<Agir> GetINDEFAgir() { DataClassesActilogDataContext db = ContextSingleton.GetDataContext(); List<Agir> list; var v = from i in db.Agir where i.facturable == null && i.NouvelIncident == true select i; list = v.ToList(); return list; } 
+12
source

Does this work?

 var v = from i in db.Agir where i.facturable == null && i.NouvelIncident == true select i; 

Linq-to-SQL should translate this to the correct SQL.

+2
source

Source: https://habr.com/ru/post/909624/


All Articles