Skip to main content

Posts

Showing posts from October, 2008

LINQ to Entities - Dynamic LINQ to Entities AND,OR

Recently I had an Advanced Search requirement which had to enable Users to specify a combination of fields to search for and the operator e.g. AND, OR and the type of comparison to do e.g. LIKE, EQUALS. The DataLayer is built upon the Entity Framework and I'm using LINQ to Entities as the query mechanism. So my overriding goal was to keep this Strongly Typed but maintainable as well. Firstly I created a generic SearchInfo object of which there would be one for each field that needed to be included in the search. public class SearchInfo<T> { public Expression<Func<T, object>> PropertySelector { get; set; } public QueryOperator Operator { get; set; } public StringComparer Comparer { get; set; } public string Value { get; set; } } public enum QueryOperator { And = 0, Or = 1 } public enum StringComparer { Equals = 0, StartsWith = 1, EndsWith = 2, Contains = 3 } Now if we just had to deal with the AND operator we could achieve this by co…

ASP.NET MVC Beta - HtmlHelper.TextBox change

I've just come across a minor change which caused the Value on my TextBox's to be set to "System.Collections.Generic.Dictionary`2[System.String,System.Object]" The HtmlHelper.TextBox method has changed. The previous (MVC Preview 5) method overloads were HtmlHelper.TextBox(string name) HtmlHelper.TextBox(string name, object htmlAttributes) HtmlHelper.TextBox(string name, string value) HtmlHelper.TextBox(string name, IDictionary htmlAttributes) HtmlHelper.TextBox(string name, string value, object htmlAttributes) HtmlHelper.TextBox(string name, string value, IDictionary htmlAttributes) These have been changed to: HtmlHelper.TextBox(string name) HtmlHelper.TextBox(string name, object value) HtmlHelper.TextBox(string name, object value, object htmlAttributes) HtmlHelper.TextBox(string name, object value, IDictionary htmlAttributes)

ASP.NET MVC Beta The type name System.Web.Mvc.IController, System.Web.Mvc could not be located

If you haven't heard by now the ASP.NET MVC Beta has been released and is available for download. NB: You will need to uninstall Preview 5 before trying to install. Big ups to the team for getting to this stage and the inclusion of jQuery is a very nice addition. Thanks to Derik for a heads up on some of the changes. There are far less breaking changes than previous releases which is great. If you're using a custom Controller Factory to inject the Controller at runtime you might come across this when you try and browse to a page. The type name System.Web.Mvc.IController, System.Web.Mvc could not be locatedBecause they have added the System.Web.Mvc, System.Web.Routing & System.Web.Abstractions assemblies to the GAC they aren't copied to the Bin by default. So make sure you right click on System.Web.Mvc , go to Properties and set Copy Local to "true". Basic stuff I know but had me scratching my head for a second or two.