locked
Filtering derived object fields from silverlight RRS feed

  • Question

  • Hi, 

     If I have type Bar derived from type Foo (Table per hierarchy in the entity framework), I can (on the server side) query it and filter a bar field like this :

                var del = from c in ctx.Foo.OfType<Bar>()
                          where c.BarField == "Baaaaah"
                          orderby c.Name
                          select c;

     

    Of course the OfType is not supported in the silverlight client library, so we have to query like this :

              var qry = (from l in be.Foo
                              where l is Bar && l.Name.Contains("A")
                          select l).Take(20);
                DataServiceQuery<Foo> dsq = (DataServiceQuery<Foo>)qry;
                dsq.BeginExecute(Callback, qry);

    But I cannot have any bar fields in the where clause.

     

    Is there a way for me to query derived objects fields from the client side using ADO.Net data services linq library ? Is there some other option ?

     

    Thanks

     

    Mark

     

     

    Tuesday, January 27, 2009 7:08 PM

Answers

  • No no we dont tell you the answer, you have to pay for this kind of support
    --------------joking aside

    Hi markygr

    I think you would be better off if you used an service operation. The code generated by the data services toolkit doesnt recreate hierarchies not that I am aware anyway, something like that would only work if you made the changes yourself on the client classes and only if you bring back all the entities so you can filter on the client side. As far as i know type filtering is not supported as an expression.

    Daniel Portella Blogger from hell http://undocnet.blogspot.com

    Daniel Portella - http://undocnet.blogspot.com - This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by markygr Wednesday, January 28, 2009 5:57 PM
    Wednesday, January 28, 2009 10:09 AM

All replies

  • No no we dont tell you the answer, you have to pay for this kind of support
    --------------joking aside

    Hi markygr

    I think you would be better off if you used an service operation. The code generated by the data services toolkit doesnt recreate hierarchies not that I am aware anyway, something like that would only work if you made the changes yourself on the client classes and only if you bring back all the entities so you can filter on the client side. As far as i know type filtering is not supported as an expression.

    Daniel Portella Blogger from hell http://undocnet.blogspot.com

    Daniel Portella - http://undocnet.blogspot.com - This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by markygr Wednesday, January 28, 2009 5:57 PM
    Wednesday, January 28, 2009 10:09 AM
  • try this:

    var qry = (from l in be.Foo
                              where l is Bar && ((Bar)I).DeriviedTypeProp == "SampleData"
                          select l).Take(20);

    • Marked as answer by Andrew ConradModerator Wednesday, January 28, 2009 4:40 PM
    • Unmarked as answer by markygr Wednesday, January 28, 2009 5:57 PM
    Wednesday, January 28, 2009 4:40 PM
    Moderator
  • Thanks Daniel, I thought I may have to do a service operation
    Wednesday, January 28, 2009 5:57 PM
  • Thanks Andrew,

    I had tried that before posting, but unfortunately I got a DataServiceException exception from data services saying that the cast was invalid.

    Digging back through the eventlog, I believe the exception was -

    FooAndBarService - System.Data.Services.DataServiceException: Not Implemented ---> System.NotSupportedException: Unable to cast the type 'Foo' to type 'Bar'. LINQ to Entities only supports casting Entity Data Model primitive types.

     Mark

     

    Wednesday, January 28, 2009 6:03 PM
  • Ah. 

    Just to be clear here this is a limitation with Entity Framework and not a limitation with ADO.NET Data Services.  (Although I acknowledge this doesn't really help people solve their scenarios).  In other words, for ADO.NET DataServices this sort of query is perfectly legal.

    Let me look into it a bit, I have seen this sort of thing work over EF, so there must be a way to get this to work without moving to service ops.

     

    Wednesday, January 28, 2009 9:57 PM
    Moderator
  • No no we dont tell you the answer, you have to pay for this kind of support
    --------------joking aside

    markygr and Andrew Conrad

    Have a look at the blog post from phaniraj Phaniraj WebLog

    there he/she explains a great deal about working with inheritance in Ado.Net Data Services.

    It is legal but you may have to do some tinkering to get it to work.

    Daniel Portella
    Blogger from hell
    http://undocnet.blogspot.com
    If this post answers you question please mark as the answer.

    Daniel Portella - http://undocnet.blogspot.com - This posting is provided "AS IS" with no warranties, and confers no rights.
    Wednesday, January 28, 2009 10:04 PM
  • No no we dont tell you the answer, you have to pay for this kind of support
    --------------joking aside

    @ Andrew Conrad
    "Marked as answer by Andrew Conrad - MSFT 5 hours 29 minutes ago
    Answer removed by markygr 4 hours 13 minutes ago"

    How cheaky andrew! Marking your own post as the answer it should be the original poster right to decide that. 

    Now i know how the top answerers are all moderators. hehe

    naughty moderators hehe.

    Daniel Portella
    Blogger from hell
    http://undocnet.blogspot.com
    If this post answers you question please mark as the answer.

    Daniel Portella - http://undocnet.blogspot.com - This posting is provided "AS IS" with no warranties, and confers no rights.
    Wednesday, January 28, 2009 10:15 PM
  • We mark our own posts as answers when we believe we have posted the correct answer.  That is how the ADO.NET Dev Team keeps track of which forums to look at, etc so that we can maximize our ability to help.   I can speak for most of the MSFT moderators in that we are not motivated by being top answerers, but that we want people to understand how to use our frameworks correctly. 

    Obviously feel free to remove the the answer flag if you think an answer we propose is incorrect.

    Thursday, January 29, 2009 1:09 AM
    Moderator
  • No no we dont tell you the answer, you have to pay for this kind of support
    --------------joking aside

    @ Andrew Conrad

    Ah I wish I could mark my own posts as the answer it would save everyone loads of time. Sorry I dont see how marking your own post as the answer helps the team track which forum to look or even how to maximize their ability to help. Infact I feel that this underminds the whole recognition program on the forums making extremely unfair to us (the community) to gain ANY recognition in this forums. 

    Plus you CAN NOT speak for most moderators you can only speak for yourself.

    It is understandable when a post that has been answered but the original poster has not marked as the answer the work around that is the "PROPOSE AS THE ANSWER" button where everyone can mark the post in question so an "Answerer" (role with in the forum) can mark that post as the answer.

    You are a moderator not an answerer.

    From the glossary

    Answerer
    An answerer is an individual who has a Profile on Forums and provides answers to question threads. The answerer can perform tasks like marking a reply to a question thread as an answer or unmarking a reply as a non-answer.

    Forum Moderator
    A Forum Moderator is an individual selected by the System Administrator to ensure that the discussions on the Forum are of high quality. By default, a moderator can perform any number of tasks within a particular forum or set of forums. This includes approving posts, moving posts, deleting posts, editing posts, or banning users. If you have a problem with a particular forum, the best place to start is with a moderator.

    !?

    Daniel Portella
    Blogger from hell
    http://undocnet.blogspot.com
    If this post answers you question please mark as the answer.

    Daniel Portella - http://undocnet.blogspot.com - This posting is provided "AS IS" with no warranties, and confers no rights. If this post is answered your question please mark as the answer and if it is helpful do like wise.
    Thursday, January 29, 2009 11:09 AM
  • Hi Daniel,

    Thanks for your advice on this.  I will look into whether changing our process makes sense.  I do think you are mssing the point that MSFT has a set of moderators that are also answerers.

    Just to be fully transparent here, I would like to give a little background.  Most of the ADO.NET Data Services team are moderators on this forum.  We all put a fixed amount of time every day working on the forums.  It is very important to us to have quick turn around and high answer rates for the forums of our products.  Getting high ratings via the forum recognition program is a complete non-goal for us. 

    I would love to rely on the community to provide answers and get the recognition they deserve.  But the reality has been for the ADO.NET Data Services forum over the past year is that questions from the community far exceed answers we are getting from the community.  Hence, the development team puts in this extra effort (often in folks free time) to provider answers on the forums. 

    I don't have official stats, but I am guessing that if one looks at the rate the MSFT folks for the ADO.NET Development team provide the correct answer - it is fairly high since we were the ones that developed the product in the first place.   Hence, I believe if we are pretty sure about a solution it is fair game to mark it as the answer.    Further, the follow up from the community on marking proposed answers as answers has been very poor in the past so by marking an response as an answer, we are able to efficiently as possible statisfy the request and also accurately record that the correct solution was proposed.

    That said, we are human and occasionally mark a solution as an answer.  So just like everyone else in the community we should have these answers revoked and held responsible for providing a different solution.

    In general, I would love to see the community step up and start improving the response time and answer rate for this forum and get the recognition.  Then we could spend that time writing more new features (which would raise even more forum traffic :-)).  But the reality is that currently just isn't happening and hence the set of moderators from the team is also the top answerers.

    Thanks -

    Andy Conrad

    ADO.NET Development Lead.

     

     

     

     

    Thursday, January 29, 2009 7:24 PM
    Moderator
  • Well Andrew,

    Thanks you much better explanation then the one before, I understand that having the users answer the questions etc, is not paying off or has not paid off. We have to remember that everyone comes here for answers (more like help) so the community, the majority of the community is not looking for giving answers but to get them. which is fine. But some of us (ie me) want to give answers. I am interested in helping out and specially I want to make a difference on the product if my bothering, questioning, answering and dicussing here it is because of that.

    Well I know moderators are forced to mark questions as answers even if it is their own threads so they can move things forward so everyone can benefit from answered questions. 

    At the moment people like me have to struggle to get even 2 medals the community doesnt bother marking, no one votes post helpful so can you undertand when when I get my nickers in a twist whe I see you marking your own thread as the answer.

    And yes you can change your process, start by making a sticky post with all known issues for astoria in version one and their solutions and work arounds. be proactive.

    regards

    Daniel Portella
    Wanna be MVP

    Daniel Portella - http://undocnet.blogspot.com - This posting is provided "AS IS" with no warranties, and confers no rights. If this post is answered your question please mark as the answer and if it is helpful do like wise.
    Saturday, January 31, 2009 1:42 AM
  • I feel so sinical asking you to be proative, you are proative at least marking the correct answers (even your own) when you are certain until proved wrong that the post has been answered. 

    I will make the sticky post, we can revise together and when you fill it coming along alright you can make it a sticky.

    fancy doing that?

    Daniel Portella - http://undocnet.blogspot.com - This posting is provided "AS IS" with no warranties, and confers no rights. If this post is answered your question please mark as the answer and if it is helpful do like wise.
    Thursday, February 12, 2009 12:33 AM