score:0
I currently have the same cases. I think the problem is the lack of recognition, by NpgSQL, of string.IsNullOrEmpty.
I replaced the test with a check on empty string, always recognizing as not NULL the input parameter.
-- bad
var data = from art in _ctx.Set<Soleo.Model.DLAR>()
from iva in _ctx.Set<Soleo.Model.DLAI>().Where(k => k.DITTA == art.DITTA && k.COD == art.CIVA).DefaultIfEmpty()
from fam in _ctx.Set<Soleo.Model.DLFA>().Where(k => k.DITTA == art.DITTA && k.COD == art.FAM).DefaultIfEmpty()
from mar in _ctx.Set<Soleo.Model.DLMA>().Where(k => k.DITTA == art.DITTA && k.COD == art.MAR).DefaultIfEmpty()
from udm in _ctx.Set<Soleo.Model.DLUM>().Where(k => k.DITTA == art.DITTA && k.COD == art.UM).DefaultIfEmpty()
where art.DITTA == DLAUTH.Config.Current.DITTA && art.COD.Contains(sel_cod) && art.DES.Contains(sel_des)
&& (string.IsNullOrEmpty(sel_fam) || string.Compare(art.FAM, sel_fam, true) == 0)
&& (string.IsNullOrEmpty(sel_mar) || string.Compare(art.MAR, sel_mar, true) == 0)
&& (art.DIS >= sel_dis_da && art.DIS <= sel_dis_a)
select new
{
COD = art.COD,
DES = art.DES,
DES_UDM = udm.DES,
DES_MAR = mar.DES,
DES_FAM = fam.DES,
DES_CIVA = iva.DES,
MAG1 = art.MAG1,
MAG2 = art.MAG2,
DES_DIS = art.DIS == 1 ? "Si" : "No"
};
-- good:
var data = from art in _ctx.Set<Soleo.Model.DLAR>()
from iva in _ctx.Set<Soleo.Model.DLAI>().Where(k => k.DITTA == art.DITTA && k.COD == art.CIVA).DefaultIfEmpty()
from fam in _ctx.Set<Soleo.Model.DLFA>().Where(k => k.DITTA == art.DITTA && k.COD == art.FAM).DefaultIfEmpty()
from mar in _ctx.Set<Soleo.Model.DLMA>().Where(k => k.DITTA == art.DITTA && k.COD == art.MAR).DefaultIfEmpty()
from udm in _ctx.Set<Soleo.Model.DLUM>().Where(k => k.DITTA == art.DITTA && k.COD == art.UM).DefaultIfEmpty()
where art.DITTA == DLAUTH.Config.Current.DITTA && art.COD.Contains(sel_cod) && art.DES.Contains(sel_des)
&& (string.Compare(sel_fam, "", true) == 0 || string.Compare(art.FAM, sel_fam, true) == 0)
&& (string.Compare(sel_mar, "", true) == 0 || string.Compare(art.MAR, sel_mar, true) == 0)
&& (art.DIS >= sel_dis_da && art.DIS <= sel_dis_a)
select new
{
COD = art.COD,
DES = art.DES,
DES_UDM = udm.DES,
DES_MAR = mar.DES,
DES_FAM = fam.DES,
DES_CIVA = iva.DES,
MAG1 = art.MAG1,
MAG2 = art.MAG2,
DES_DIS = art.DIS == 1 ? "Si" : "No"
};
But I do not think this is the solution. I will report the case to NpgSQL.
Source: stackoverflow.com
Related Articles
- Include where clause on linq query when param is not null Npgsql
- Linq Query with a Where clause in an Include statement
- Linq query works with null but not int? in where clause
- LINQ query null exception when Where returns 0 rows
- How can I check for null values in this linq query where clause
- Linq query where First() appears to return null when results are not found
- Left Join on Linq query when also using the Where clause on joint table
- Include null cells in Linq query from DB in C# code
- LINQ query dropping includes when adding `.Contains()` in where clause
- LINQ OUTER JOIN Query - Null in Where clause not working
- LINQ query performance when applying Where clause
- LINQ query returns null reference only after adding where clause
- Linq Where clause not returning what I expect when performing String.Contains(String) on a null string
- "OR " condition in where clause of linq query is returning null
- Stored Procedure Results Return Null When Where Clause is Added in LINQ
- Linq query where clause to include the UTC Timezone conversion
- Where Clause is not applied when converting the query from LINQ (EF) to SQL
- List is null when checking for two conditions in where clause with boolean datatype in Linq
- Linq query where clause returning null
- LINQ: adding where clause only when a value is not null
- LINQ query to perform a projection, skipping or wrapping exceptions where source throws on IEnumerable.GetNext()
- linq where clause and count result in null exception
- linq where clause when id is in an array
- Using string.compare in a linq query where clause
- LINQ query with a WHERE clause with multiple conditions
- When using a LINQ Where clause on a Dictionary, how can I return a dictionary of the same type?
- Linq where clause with multiple conditions and null check
- Pass int array in where clause of LINQ Query
- When to use lambda expressions instead of a Where clause in LINQ
- Linq to SQL: Where clause comparing a Nullable<DateTime> with a SQL datetime null column
- Delete method in WCF
- Include / ThenInclude with where in EF Core
- Get values from a nested list with a LINQ expression
- json result,results "undefined" in view mvc
- Function to linq conversion
- LINQ SELECT with Max and Where in SUBQUERY
- Using LINQ or equivalent to format the console output of List objects
- Overriding LINQ extension methods
- Calling System.Linq.Queryable methods using types resolved at runtime
- Selecting HTML Content of a node LINQ XML
- Using linq to iterate through winform menuitems and change a property value
- Calculate sum using LINQ
- MongoDB LINQ: Count with predicate inside Where not supported?
- Linq to Entities strange results
- LINQ Order By Descending with Null Values on Bottom
- Use Linq to search through list
- I want to create a common unit test function to check all functions based on parameter
- How to use EXIST and NOT EXIST clause using lambda expression
- How can I subtract two dates and get a new date converted in minutes?
- How to insert a record with LINQ and C# and return the Primary Key of that record