locked
Custom Queries in Dynamic Data RRS feed

  • Question

  • User-1807811555 posted

    Hello!

    I'm developing a ASP .NET Application using Web Forms and i'm trying to implement Dynamic Data Scaffolding. 

    I have successfully implemented it in a Multi-Project Solution. 

    My problem right now is how can i customize the queries used in Dynamic Data "Views".

    For example for the List.aspx if I only want to show the items that have a certain value in a certain "column" how can i add a where clause to the queries used/generated by Dynamic Data?

    Thanks, 

    Francisco

    Monday, April 14, 2014 6:26 AM

Answers

  • User-1807811555 posted

    I think I found a solution even though i don't know if it is the best one but....

    In the List.aspx there is a QueryExtender so if i add a CustomExpression i can than specify a query expression to be used.

    <asp:QueryExtender TargetControlID="GridDataSource" ID="GridQueryExtender" runat="server">

      <asp:DynamicFilterExpression ControlID="FilterRepeater" />

      <asp:CustomExpression OnQuerying="FilterStuff" />

    </asp:QueryExtender>

    After that i created a custom partial class in ~/DynamicData/CustomPages/Things/List.aspx.cs

    namespace Scaffold.WebSite

    {

        public partial class List

        {

            protected void FilterStuff(object sender, CustomExpressionEventArgs e)

            {

                e.Query = from p in e.Query.Cast<Things>()

                        where p.ID >= 12

                        select p;

            }

        }

    }

    Hope it helps someone eith the same problem Laughing.

    Thanks, 

    Francisco

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 14, 2014 7:28 AM

All replies

  • User-1807811555 posted

    I think I found a solution even though i don't know if it is the best one but....

    In the List.aspx there is a QueryExtender so if i add a CustomExpression i can than specify a query expression to be used.

    <asp:QueryExtender TargetControlID="GridDataSource" ID="GridQueryExtender" runat="server">

      <asp:DynamicFilterExpression ControlID="FilterRepeater" />

      <asp:CustomExpression OnQuerying="FilterStuff" />

    </asp:QueryExtender>

    After that i created a custom partial class in ~/DynamicData/CustomPages/Things/List.aspx.cs

    namespace Scaffold.WebSite

    {

        public partial class List

        {

            protected void FilterStuff(object sender, CustomExpressionEventArgs e)

            {

                e.Query = from p in e.Query.Cast<Things>()

                        where p.ID >= 12

                        select p;

            }

        }

    }

    Hope it helps someone eith the same problem Laughing.

    Thanks, 

    Francisco

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 14, 2014 7:28 AM
  • User-330204900 posted

    your best bet wouold be to use Model binding sadly we don't have a scaffolding solution for that at the moment.

    Monday, April 14, 2014 12:43 PM