ASP.net mvc application reference error

Posted on 2014-09-11
Medium Priority
Last Modified: 2014-09-15
I saw this ASP.NET MVC example  on using jqgrid


In this example they are using Lind database model.

I switched up the data model in my example to use Entity Database First model. So my data model is called HaackOverflowEF.edmx.

The example code in the link above was done using Visual Studio 2010.

So when I used Visual Studio 2010 and ran my application, it works just fine.  
My Visual Studio 2010 directory looks like this:

my visual studio 2010 directory
The code for my HomeController.cs in my Visual Studio 2010 application looks like this:

// The example is a modification of the example created by Phil Haack
// see http://haacked.com/archive/2009/04/14/using-jquery-grid-with-asp.net-mvc.aspx
using System.Linq;
using System.Web.Mvc;
using jqGridWeb.Models;
using System.Data.Objects;
using System.Web.Script.Serialization;
using System.Collections.Generic;
using System.Text;
using System;
using System.Reflection;

namespace jqGridWeb.Controllers
    // to send exceptions as json we define [HandleJsonException] attribute
    public class ExceptionInformation {
        public string Message { get; set; }
        public string Source { get; set; }
        public string StackTrace { get; set; }
    public class HandleJsonExceptionAttribute : ActionFilterAttribute {
        // next class example are from the http://www.dotnetcurry.com/ShowArticle.aspx?ID=496
        public override void OnActionExecuted(ActionExecutedContext filterContext) {
            if (filterContext.HttpContext.Request.IsAjaxRequest() && filterContext.Exception != null) {
                filterContext.HttpContext.Response.StatusCode =

                var exInfo = new List<ExceptionInformation>();
                for (Exception ex = filterContext.Exception; ex != null; ex = ex.InnerException) {
                    PropertyInfo propertyInfo = ex.GetType().GetProperty ("ErrorCode");
                    exInfo.Add(new ExceptionInformation() {
                        Message = ex.Message,
                        Source = ex.Source,
                        StackTrace = ex.StackTrace
                filterContext.Result = new JsonResult() {Data=exInfo};
                filterContext.ExceptionHandled = true;

    public class Filters {
        public enum GroupOp {
        public enum Operations {
            eq, // "equal"
            ne, // "not equal"
            lt, // "less"
            le, // "less or equal"
            gt, // "greater"
            ge, // "greater or equal"
            bw, // "begins with"
            bn, // "does not begin with"
            //in, // "in"
            //ni, // "not in"
            ew, // "ends with"
            en, // "does not end with"
            cn, // "contains"
            nc  // "does not contain"
        public class Rule {
            public string field { get; set; }
            public Operations op { get; set; }
            public string data { get; set; }

        public GroupOp groupOp { get; set; }
        public List<Rule> rules { get; set; }
        private static readonly string[] FormatMapping = {
            "(it.{0} = @p{1})",                 // "eq" - equal
            "(it.{0} <> @p{1})",                // "ne" - not equal
            "(it.{0} < @p{1})",                 // "lt" - less than
            "(it.{0} <= @p{1})",                // "le" - less than or equal to
            "(it.{0} > @p{1})",                 // "gt" - greater than
            "(it.{0} >= @p{1})",                // "ge" - greater than or equal to
            "(it.{0} LIKE (@p{1}+'%'))",        // "bw" - begins with
            "(it.{0} NOT LIKE (@p{1}+'%'))",    // "bn" - does not begin with
            "(it.{0} LIKE ('%'+@p{1}))",        // "ew" - ends with
            "(it.{0} NOT LIKE ('%'+@p{1}))",    // "en" - does not end with
            "(it.{0} LIKE ('%'+@p{1}+'%'))",    // "cn" - contains
            "(it.{0} NOT LIKE ('%'+@p{1}+'%'))" //" nc" - does not contain
        internal ObjectQuery<T> FilterObjectSet<T> (ObjectQuery<T> inputQuery) where T : class {
            if (rules.Count <= 0)
                return inputQuery;

            var sb = new StringBuilder();
            var objParams = new List<ObjectParameter>(rules.Count);

            foreach (Rule rule in rules) {
                PropertyInfo propertyInfo = typeof (T).GetProperty (rule.field);
                if (propertyInfo == null)
                    continue; // skip wrong entries

                if (sb.Length != 0)

                var iParam = objParams.Count;
                sb.AppendFormat(FormatMapping[(int)rule.op], rule.field, iParam);

                ObjectParameter param;
                switch (propertyInfo.PropertyType.FullName) {
                    case "System.Int32":  // int
                        param = new ObjectParameter ("p" + iParam, Int32.Parse (rule.data));
                    case "System.Int64":  // bigint
                        param = new ObjectParameter ("p" + iParam, Int64.Parse (rule.data));
                    case "System.Int16":  // smallint
                        param = new ObjectParameter ("p" + iParam, Int16.Parse (rule.data));
                    case "System.SByte":  // tinyint
                        param = new ObjectParameter ("p" + iParam, SByte.Parse (rule.data));
                    case "System.Single": // Edm.Single, in SQL: float
                        param = new ObjectParameter ("p" + iParam, Single.Parse (rule.data));
                    case "System.Double": // float(53), double precision
                        param = new ObjectParameter ("p" + iParam, Double.Parse (rule.data));
                    case "System.Boolean": // Edm.Boolean, in SQL: bit
                        param = new ObjectParameter ("p" + iParam,
                            String.Compare(rule.data, "1", StringComparison.Ordinal) == 0 ||
                            String.Compare(rule.data, "yes", StringComparison.OrdinalIgnoreCase) == 0 ||
                            String.Compare(rule.data, "true", StringComparison.OrdinalIgnoreCase) == 0?
                        // TODO: Extend to other data types
                        // binary, date, datetimeoffset,
                        // decimal, numeric,
                        // money, smallmoney
                        // and so on

                        param = new ObjectParameter ("p" + iParam, rule.data);
                objParams.Add (param);

            ObjectQuery<T> filteredQuery = inputQuery.Where (sb.ToString ());
            foreach (var objParam in objParams)
                filteredQuery.Parameters.Add (objParam);

            return filteredQuery;

    public class HomeController : Controller
        public ActionResult Index()
            ViewData["Message"] = "Welcome to ASP.NET MVC!";
            return View();

        public JsonResult DynamicGridData(string sidx, string sord, int page, int rows, bool _search, string filters)

            var context = new HaackOverflowEntities();
            var serializer = new JavaScriptSerializer();
            Filters f = (!_search || string.IsNullOrEmpty (filters)) ? null : serializer.Deserialize<Filters> (filters);
            ObjectQuery<Question> filteredQuery =
                (f == null ? context.Questions : f.FilterObjectSet (context.Questions));
            filteredQuery.MergeOption = MergeOption.NoTracking; // we don't want to update the data
            var totalRecords = filteredQuery.Count();

            var pagedQuery = filteredQuery.Skip ("it." + sidx + " " + sord, "@skip",
                                                new ObjectParameter ("skip", (page - 1) * rows))
                                         .Top ("@limit", new ObjectParameter ("limit", rows));
            // to be able to use ToString() below which is NOT exist in the LINQ to Entity
            var queryDetails = (from item in pagedQuery
                                select new { item.Id, item.Votes, item.Title }).ToList();

            return Json(new {
                            total = (totalRecords + rows - 1) / rows,
                            records = totalRecords,
                            rows = (from item in queryDetails
                                    select new[] {

        public ActionResult About ()
            return View();

Open in new window

Like i said, my Visual Studio 2010 application ran just fine.

So since i'm using Visual Studio 2013 Ultimate , I tried to open my Visual Studio 2010 project with it but it would not let me upgrade it and said project not supported.

So then I figured I would create the exact same project from scratch in Visual Studio 2013 instead of converting it.

So then my Visual Studio 2013 ASP.NET MVC application looks like this and I'm using Entity Framework 6.

I have the exact same code and directory structure as in my Visual Studio 2010 project. I re-created the entity model in this visual studio 2013 project.

But now I'm getting one error. The image below shows the error.

error message
Anyone know why I'm getting this error or am I missing something?

The code is the same in both projects but I'm getting this one error.
Question by:maqskywalker
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Author Comment

ID: 40318079
I did a little more research.

So I created a different jqgrid exampl. This time i did a ASP.NET Web Forms example.

So I did my example using Visual Studio 2010 , C#, Web Forms and targeting .NET 4.
In my project i installed Entity Framework 6.1.1 by typing this at the console manager.    


Install-Package EntityFramework

So after I Installed Entity Framework 6.1.1 in my Visual Studio 2010 project I then created Northwind.edmx

My jqgrid just binds the Employees table from that model.
So then I ran my project and it works just fine.

This is what my model in solution explorer looks like:

my Northwind.edmx model in Visual Studio 2010 Solution Explorer
So then I created the exact same example in Visual Studio 2013 and I also used Entity Framework 6.1.1.

But I noticed one thing, in my Visual Studio 2013 when I created my Northwind.edmx model.  When I look at the structure in Solution Explorer it looks a little different than it does in Visual Studio 2010.

This is what it looks like in Visual Studio 2013:

my Northwind.edmx model in Visual Studio 2013 Solution Explorer
If you look at my picture of Northwind.edmx in Visual Studio 2010 above, that one has some items that containt ObjectSet  in it.
Whereas my Visual Studio 2013 model in solution explorer doesn't have these items and I believe that is why I'm getting the exact same error in both of my visual studio 2013 examples.

Both my examples work just when when I use EF 6.1.1 in Visual Studio 2010 but I get this same error in both my example when I use EF 6.1.1 in Visual Studio 2013.

Anyone know why I'm getting this error? How do i fix it?

The line of code I'm getting the error is this.

            ObjectQuery<Employee> filteredQuery =
                f == null ? context.Employees : f.FilterObjectSet(context.Employees);

Do I have to change the syntax on this line?
LVL 75

Accepted Solution

käµfm³d   👽 earned 2000 total points
ID: 40318094
Your original code was using type inference. For whatever reason, 2013 cannot determine the types to plug in to the generic method's type parameters (during compilation). Just specify them yourself by including the angle brackets and an appropriate type.


...  f.FilterObjectSet<[insert type her]>(context.Questions));

Open in new window


Author Comment

ID: 40319966
I'm confused, so what would i type inside the < >   ?

My Entity Model called Northwind.edmx just has the Employees table of the Northwind database modeled in the diagram.

The only columns I'm using in my grid are  EmployeeID which is Integer, LastName which is nvarchar(20), FirstName which is nvarchar(10) and Title which is nvarchar(30)

So would my line look like this? what would I type inside  the angle brackets?

ObjectQuery<Employee> filteredQuery =
                f == null ? context.Employees : f.FilterObjectSet<??????????>(context.Employees);

I saw this link, with possible solution, but that doesn't make sense to me.


Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses
Course of the Month10 days, 12 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question