I'm using Linq-to-DB (linq2db, linq2db.EntityFrameworkCore).
My software supports several database providers (SQL Server, PostgreSQL). There is a case when I need to use a provider specific function for SQL Server, and for PostgreSQL use an alternative option, or ignore it.
For example, I need this code to work with two providers.
In the case of SQL Server, the ISJSON
must be performed, and in the case of PostgreSQL, it must be ignored:
var d1 = db.Invoice
.Where(i => SqlFn.IsJson(i.InvoiceState) == true)
.ToLinqToDB().ToList();
Now in the case of PostgreSQL I get an error
'IsJson(i.InvoiceState)' cannot be converted to SQL
How to do this correctly?
1条答案
按热度按时间gcuhipw91#
You can create other function which handles other providers:
And use in your queries: