Filter on datetime with empty/null value in dataservice

I’m trying to use dataservice with filters to get all variants that has no value in a specific datetime field. Is this possible?

The following code runs, but returns no values (should be 1 variant).

                ICollection<DistributorLitiumProductInfoModel> prods = query
                    .Filter(filter => filter
                        .Bool(boolFilter => boolFilter.Must(boolFilterMust => boolFilterMust
                            .Field(ProductFieldNameConstants.ExpiredFromDistributors, "eq", "null"))
                        ))
                    .ToList()

Also tried to set the values to null and DateTime.MinValue but both of these will throw errors.

Litium version: 7.6.1

There’s a null operator you can use for this type of query. See Field operators and data service Q&A

ICollection<DistributorLitiumProductInfoModel> prods = query
	.Filter(filter => filter
		.Bool(boolFilter => boolFilter.Must(boolFilterMust => boolFilterMust
			.Field(ProductFieldNameConstants.ExpiredFromDistributors, "null", null))
		))
	.ToList()

Thanks, works as it should. I suppose the any option would be equal to not null?

Do you also know if it is possible to only retrieve one field (in this case I am only really interested in the article no field) or is the best option to do ToList() and then select the required fields?

Yes, exactly. any is any value at all.

You’ll get the entire entity in your list, it’s not possible to get just a single field for an entity.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.