Filter entity on enum property throws error

6 posts, 1 answers
  1. Masoud
    Masoud avatar
    61 posts
    Member since:
    Aug 2011

    Posted 21 Mar 2012 Link to this post

    Hi there,

    I am trying to filter using Enum properties and getting an exception.

    I want to filter type BasisBaumEntity. The property I would like to filter against is called BewBpflErhaltfaehigKey of type Erhaltfaehigkeit which is an enum (that inherits from byte).  

    I am creating the filter programatically: 
    FilterDescriptor filterDescriptor = new FilterDescriptor("BewBpflErhaltfaehigKey", FilterOperator.IsEqualTo, Erhaltfaehigkeit.Kurzfristig 

    Here is the request as recorded by Fiddler
    @
    MessageRoot@ QueryOptions@
    QueryOptionName�whereValue�9(it.BewBpflErhaltfaehigKey==Erhaltfaehigkeit.Kurzfristig)@
    QueryOptionName�orderbyValue�it.Nr@
    QueryOptionName�takeValue�24@
    QueryOptionName�includeTotalCountValue�True@
    GetBasisBaumshttp://tempuri.org/


    The exception I receive is 
    Property or field "Erhaltfaehigkeit" is not declared in type in "BasisBaumEntity".
    I tried to decorate the Enum with [DataContract] attribute, and decorated the members with [EnumMember].  Still, WCF RIA server side ist trying to locate Erhaltfaehigkeit as a field or property in BasisBaumEntity.  

    Jeff Handler from the WCF RIA Team states that such filtering should be possible  (http://jeffhandley.com/archive/2010/11/19/DomainDataSourceEnumFilters.aspx).  
    If you wish I can send you the stacktrace of the exception!

    I would really appreciate you help on this issue!


    Best
  2. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 21 Mar 2012 Link to this post

    Hi,

    This really seems like a WCF RIA Services-related  issue and we do not believe that it is connected with Telerik controls. 

    RadDomainDataSource uses the WCF RIA DomainContext and EntityQuery API for absolutely everything it does. In other words, it steps on WCF RIA Services -- it does not replace them.

    Can you successfully filter on this enum property if you do not use any Telerik controls? For example, you can try with the stock Microsoft DomainDataSource or you can directly use the DomainContext and try to load an EntityQuery.Where(<<filter on the enum prop here>>). 

    What are the results? Are they different or are they the same?

    Let us know if the stock Microsoft DomainDataSource works successfully and ours does not.

    All the best,
    Ross
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. DevCraft banner
  4. Masoud
    Masoud avatar
    61 posts
    Member since:
    Aug 2011

    Posted 21 Mar 2012 Link to this post

    Hi Ross,

    thank you for your reply!

    I now managed to test the MS DomainDataSource.  It turns out that DomainDataSource casts Enum values to numeric representations.  Following is the request as captured by Fiddler
    @
    MessageRoot@ QueryOptions@
    QueryOptionName�whereValue�\(it.BewBpflErhaltfaehigKey==0)@
    GetBasisBaumshttp://tempuri.org/

    Running the same FilterDescriptor against the RadDomainSource the enum values are not cast to a numeric but rather handed over as string:

    QueryOptionName�whereValue�9(it.BewBpflErhaltfaehigKey==Erhaltfaehigkeit.Kurzfristig)@ 

    This causes an exception with the Domain Service on the server.

    Can you please suggest a way to use the RadDomainSource with enums?

    Best regards


  5. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 21 Mar 2012 Link to this post

    Hi,

    Thanks for the information. I will immediately investigate what do we append on the EntityQuery when there is an enum value in the FilterDescriptor.

    By the way, do you have any kind of a dummy sample project with dummy data that I can debug in order to see what is going on. I suppose that since you have played around with this issue, you might have some kind of a dummy project that I could use.

    All the best,
    Ross
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  6. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 21 Mar 2012 Link to this post

    Hi,

    No need to send me anything. I reproduced it. Apparently MS are converting the enum value to int before sending it to the server.

    I will try to make RadDomainDataSource do the same and I will contact you when I am ready.

    Kind regards,
    Ross
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  7. Answer
    Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 26 Mar 2012 Link to this post

    Hi,

    I managed to fix the bug.

    Unfortunately, the fix will not be able to make it in the Service Pack, since we have a code freeze already. The fix will be released with our first "Latest Internal Build" that will come out after the Service Pack, which I reckon will be in about 5-10 days.

    All the best,
    Ross
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Back to Top
DevCraft banner