locked
Filtering on public properties RRS feed

  • Question

  • User-1336852631 posted

    I've added a public property to one of my classes as follows:

            public string Client
            {
                get
                {
                    if (this.Projects.FirstOrDefault() == null || this.Projects.FirstOrDefault().Client == null)
                    {
                        return "";
                    }
                    else
                    {
                        return this.Projects.FirstOrDefault().Client.ClientName;
                    }
                }
            }

    Does anybody know a way of adding a filter to the list page for this public property.  I want a drop down list of Clients on an Orders list page, where Orders is related to one or more Projects and each Project is related a single Clients.

    Wednesday, August 22, 2012 12:36 PM

Answers

  • User-330204900 posted

    OK Biga, if this is a Custom property i.e. one that only exists in the model not the DB then there is no way and this is because the filter is applied int he DB as an SQL Select query not the data layer. The way I get around this is by using a computed column see computed_column_definition (Transact-SQL) the use my dropdown where filter from NuGet.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, August 26, 2012 10:00 AM

All replies

  • User3866881 posted

    Does anybody know a way of adding a filter to the list page for this public property.

    Hi,

    I don't understand what you want to do with this property……?Do you want to filter records with thei property as a "where" condition?

    Thursday, August 23, 2012 9:33 PM
  • User-1336852631 posted
    Hi Yes, that's correct.
    Friday, August 24, 2012 8:36 AM
  • User3866881 posted

    Hi Yes, that's correct.

    Hi,

    If you want to do filtering with the Dropdownlists……I still suggest you tring to save the name into a Dropdownlist and do filtering as what it used to be instead of yours……and to be honest, to extend yours isn't an easy way……

    Reguards!

    Saturday, August 25, 2012 4:52 AM
  • User-1336852631 posted

    Thanks for the reply.   Are you saying save the client names into a drop down list and then on the drop down list selection event filter based how I've defined the public property?    Can you give me an idea of how you would filter the GridView from a drop down list selection event?

    Saturday, August 25, 2012 6:14 AM
  • User-330204900 posted

    Hi Biga, is this Dynamic Data?

    Saturday, August 25, 2012 10:51 AM
  • User-1336852631 posted

    Hi Steve,

    Yes it's dynamic data.

     

    Saturday, August 25, 2012 11:43 AM
  • User-330204900 posted

    OK Biga, if this is a Custom property i.e. one that only exists in the model not the DB then there is no way and this is because the filter is applied int he DB as an SQL Select query not the data layer. The way I get around this is by using a computed column see computed_column_definition (Transact-SQL) the use my dropdown where filter from NuGet.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, August 26, 2012 10:00 AM
  • User-1336852631 posted

    Thanks for the reply Steve.  Its an example of hitting the limitations of DD then and a for me it's reason to consider moving to MVC.

    Sunday, August 26, 2012 11:54 AM
  • User-330204900 posted

    Hi Biga, the trade off is really simple between Web Forms DD and MVC it's the amount oc code you have to write against level of control of HTML.

    I always go for Computed Columns as the issue you mentioned is not a limitation of DD but EF and most other ORMs.

    Monday, August 27, 2012 4:32 AM
  • User-1336852631 posted
    Thanks Steve. Adding logic into the database in order to filter in the user interface seems incorrect to me (although I appreciate it's a compromise and there is no alternative when using DD). I'll continue to use DD where it gives the benefits you've described and use MVC where I need a little more control. It is possible to mix the two in the same application I understand.
    Monday, August 27, 2012 6:20 AM
  • User-330204900 posted

    It is possible to mix DD and MVC but be aware that that the issue you described above is not a limitation of DD it's a designe limitation of the Entity Framework and could be worked around even in DD you will have the same filtering issues in MVC with EF.

    Monday, August 27, 2012 11:51 AM