No coercion operator is defined between types 'System.Int32' and 'System.Nullable`1[System.DateTime]'

Hello, after Upgrading from 5.x to 6.x we have a lot of changes in our Querys with Filter and FilterParameters...
we fixed a lot after reading:
https://forum.radzen.com/t/just-released-our-new-major-version-of-radzen-blazor-6-0-0-without-reference-to-system-linq-dynamic-core-nuget-package/19748/10

but we have a problem with a FilterParameter DateTime.Now.AddMonths(-6)

new Query()
{
    Expand = "PfuscherbeziehungAkts, PfuscherbeziehungAkts.PfuscherbeziehungAktFachgruppes",
    Filter = filter,
    FilterParameters = new object[] {
            search,
            _Jahr,
            ddlAktzustand_ID,
            ddlMeldungstyp_ID,
            ddlStatus,
            ddlVerfahrensabschluss_ID,
            ddlBehörde_ID,
            ddlErmittler_ID,
            ddlFGR_ID,
            DateTime.Now,
            DateTime.Now.AddMonths(-6),
            ddlMeldertyp_ID
    },
    OrderBy = $"Meldungsdatum desc"
});

we always get an error:
No coercion operator is defined between types 'System.Int32' and 'System.Nullable`1[System.DateTime]'

Error: System.InvalidOperationException: Invalid predicate: i => i.Jahr == 2024 && i.PfuscherbeziehungAkts.Any(i => i.PfuscherbeziehungAktFachgruppes.Any(i => i.ErledigtAm < 20240)) && (i.Aktenzahl.StartsWith("") || i.Akt_ID.ToString().StartsWith("") || i.Übertretungspostleitzahl.StartsWith("") || i.Übertretungsort.StartsWith("") || i.Übertretungsstrasse.StartsWith("") || i.Pfuscherliste.StartsWith("") || i.Tätigkeiten.StartsWith("") || i.Notiz.StartsWith(""))

the problem is this i.ErledigtAm < 20240 >> 20240 is not a datetime!!

how to solve this?

You cannot compare these types - make sure you are passing the right parameter value.

ErledigtAm is a datetime and DateTime.Now.AddMonths(-6) is also a datetime

how to pass a datetime wich is 6 months in the past then?

I'm not sure how your filter string looks however this value might comes from ddlMeldertyp_ID

this is wierd

  • Parameter @9 is DateTime.Now
  • Parameter @10 is DateTime.Now.AddMonths(-6)
    if I use
    $@"i.PfuscherbeziehungAkts.Any(i => i.PfuscherbeziehungAktFachgruppes.Any(i => i.ErledigtAm < @9))

it works and if I use
$@"i.PfuscherbeziehungAkts.Any(i => i.PfuscherbeziehungAktFachgruppes.Any(i => i.ErledigtAm < @10))

not - I didn't understand this

I was able to replicate the problem - fix will be released immediately!

1 Like

similar Problem with that parameters:

            pfuscher = await PDBService.GetPfuschers(
                new Query()
                {
                    Expand = "PfuscherbeziehungAkts",
                    Filter = filter,
                    FilterParameters = new object[] {
                        search,
                        ddlVerfahrensabschluss_ID,
                        GeburtsdatumVon?.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ"),
                        GeburtsdatumBis?.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ"),
                        ErhebungsdatumVon?.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ"),
                        ErhebungsdatumBis?.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
                    },
                    OrderBy = $"Pfuschername"
                });

Error: System.InvalidOperationException: Invalid predicate: i => i.Geburtsdatum == "2025-03-31T22:00:00Z" && (i.Pfuschername.StartsWith("") || i.Titel.StartsWith("") || i.Anrede.StartsWith("") || i.Postleitzahl.StartsWith("") || i.Ort.StartsWith("") || i.Strasse.StartsWith("") || i.Sozialversicherungsnummer.StartsWith("") || i.Beruf.StartsWith("") || i.Notiz.StartsWith("") || i.Mitglied_ID.ToString().StartsWith(""))

  • ---> System.InvalidOperationException: No coercion operator is defined between types 'System.String' and 'System.Nullable`1[System.DateTime]'.*

Just published Radzen.Blazor 6.6.4 with fix included.