This project is read-only.

Along with the project is a sample 3-layer application using the Dynamic Query project. This is a tutorial based on the sample application. If you want more complete examples, please see test cases for query binder, and test cases for query parser.

1. Download the source code using TFS or Subversion.

2. Prepare the databse : create an empty database named Shop. Make sure to check the connection string in the web.config file matches your configuration.

3. Run the all the tests to create some sample data.(Or you can create by yourself)

4. Register model binder in Appliaction_Start

   ModelBinders.Binders.Add(typeof(QueryDescriptor), new QueryDescriptorBinder());

5. Use QueryEditor extension method to create filter condition:

        <form class=".form-search">
            @Html.QueryTextbox("Name", "Product Name", QueryOperator.CONTAINS)
            @Html.QueryTextbox("Category.Name", "Product Category", QueryOperator.CONTAINS)
            @Html.QueryTextbox("Price.1", "Price Between", QueryOperator.GREATEROREQUAL,"decimal")
            @Html.QueryTextbox("Price.2", "", QueryOperator.LESSOREQUAL,"decimal")
            <input type="submit" value="Search" class="btn"/>

    The rule is quite straight-forward. The first parameter is the property name which you need to filter, it’s case sensitive. Navigation property is also supported.If a property appears more than once, use a numeric postfix to distinguish them. The second paramter is the label before the textbox. The third is the logical operator.The last one is the data type of the property.Supported types are:decimal,float,double,int,string.


6. In action methods, data are automatically bound to the QueryDescriptor:

        public ActionResult Index(QueryDescriptor descriptor)
            ShopContainer ctx = new ShopContainer();
            var result = ctx.Products.Query(descriptor);
            return View("Product",result);

Last edited Nov 30, 2012 at 4:46 AM by yinzixin, version 4


No comments yet.