New Posts New Posts RSS Feed: Error creating PredicateDescription
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Error creating PredicateDescription

 Post Reply Post Reply
Author
kpinniger View Drop Down
Newbie
Newbie
Avatar

Joined: 10-Mar-2010
Location: Atlanta, GA USA
Posts: 7
Post Options Post Options   Quote kpinniger Quote  Post ReplyReply Direct Link To This Post Topic: Error creating PredicateDescription
    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

Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 20-Dec-2011 at 12:25pm

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]
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post 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);
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down