Print Page | Close Window

Error creating PredicateDescription

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3173
Printed Date: 07-Jun-2024 at 11:24pm


Topic: Error creating PredicateDescription
Posted By: kpinniger
Subject: Error creating PredicateDescription
Date Posted: 20-Dec-2011 at 5:36am

What version was this fixed in, we are using 6.1.3.  I did not see any PredicateBuilder fixes in the release notes for 6.1.4.

PredicateDescription predicate = PredicateBuilder.Make(fieldName, FilterOperator.InList, list);

If there is a null item in the list, the query.Where(predicate) will throw a null reference exception




Replies:
Posted By: DenisK
Date Posted: 20-Dec-2011 at 12:25pm
Note: This was moved from this post.  http://www.ideablade.com/forum/forum_posts.asp?TID=2806&PID=12283#12283 - http://www.ideablade.com/forum/forum_posts.asp?TID=2806&PID=12283#12283

Hi kpinniger;

I'm moving this to a new post as it is a different issue. I was able to duplicate this. Let me file a bug report and get back to you with a workaround if any.

FYI, the bug on the previous post was fixed in 6.1.2. Here's the description of the bug in the Release Notes.

PredicateDescriptions using ‘FilterOperator.InList’ will no longer throw an ArgumentException when used with nullable properties. [D1827]


Posted By: DenisK
Date Posted: 28-Dec-2011 at 5:07pm
Hi kpinniger,

The bug for this has been fixed. To clarify, the bug fix for this is a clearer exception message rather than a null ref exception. 

Below is the correct way to build a predicate with a null item in the list.

var list = new short?[] { 0, 1, 2, 3 }.ToList();
var p = new PredicateDescription(typeof(Product), Product.EntityPropertyNames.UnitsInStock, FilterOperator.InList, list);
var p2 = new PredicateDescription(typeof(Product), Product.EntityPropertyNames.UnitsInStock, FilterOperator.IsEqualTo, null)
var p3 = p.Or(p2);
var q = EntityQuery.Create(typeof(Product)).Where(p3);



Print Page | Close Window