locked
Query filter on Computed field or Relationship field is it possible? RRS feed

  • Question

  • Hi, I am trying to create a Query on an Entity which contains Relationship link to another Entity.   But in the Filter I don't see the Relationship Data field to select nor my Computed fields am I missing something?

    Basically I want to create a custom Search screen using the either the Computed field which return the string value of my Related table or the Relationship Data field since I don't see them in the selection how can I set the Parameters required for my custom Search screen?


    • Edited by L Vu Friday, November 4, 2011 6:45 PM
    Friday, November 4, 2011 6:33 PM

Answers

  • Have you tried using a parameterized Query instead and doing your filter in the preprocess method? Something like this below. Change the screen query on left to by your new filter query and it should add the parameter screen item automatically. You can then drag that parm to the screen and use that item as the filter box.

            partial void BooksByAuthorAge_PreprocessQuery(int? Age, ref IQueryable<Book> query)
            {
                if (!Age.HasValue) return; // All
                query = query.Where(b=>b.BookAuthors.Any(ba=>ba.Author.Age==Age));
            } 

    Friday, November 4, 2011 7:21 PM

All replies

  • Hi L Vu

    You can't use computed property for filter because in filter you can use only properties from entity.

    Best regards


    Spaso Lazarevic
    Friday, November 4, 2011 6:53 PM
  • So how do I create custom search for my related Data field?  It is an integer, I can creating a search on an integer but doesn't make sense to the users.  I want to allow users to search on the String value of the look up field instead.

    Here is my Entity
    ID
    LocationID  <== This Data field is a relationship to an Entity Locations which contains the Location_Name, this is the field I want to filter on.

    So my Entity have Data like this
    1   <= This is my ID record
    1   <= This is the Location RecordID 

    2
    1

    Friday, November 4, 2011 6:58 PM
  • Have you tried using a parameterized Query instead and doing your filter in the preprocess method? Something like this below. Change the screen query on left to by your new filter query and it should add the parameter screen item automatically. You can then drag that parm to the screen and use that item as the filter box.

            partial void BooksByAuthorAge_PreprocessQuery(int? Age, ref IQueryable<Book> query)
            {
                if (!Age.HasValue) return; // All
                query = query.Where(b=>b.BookAuthors.Any(ba=>ba.Author.Age==Age));
            } 

    Friday, November 4, 2011 7:21 PM
  • Thanks I will give it a try

     

    Friday, November 4, 2011 8:10 PM