Solved mvc application reference error

Posted on 2014-09-11
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
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
        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 (;
                    case "System.Int64":  // bigint
                        param = new ObjectParameter ("p" + iParam, Int64.Parse (;
                    case "System.Int16":  // smallint
                        param = new ObjectParameter ("p" + iParam, Int16.Parse (;
                    case "System.SByte":  // tinyint
                        param = new ObjectParameter ("p" + iParam, SByte.Parse (;
                    case "System.Single": // Edm.Single, in SQL: float
                        param = new ObjectParameter ("p" + iParam, Single.Parse (;
                    case "System.Double": // float(53), double precision
                        param = new ObjectParameter ("p" + iParam, Double.Parse (;
                    case "System.Boolean": // Edm.Boolean, in SQL: bit
                        param = new ObjectParameter ("p" + iParam,
                            String.Compare(, "1", StringComparison.Ordinal) == 0 ||
                            String.Compare(, "yes", StringComparison.OrdinalIgnoreCase) == 0 ||
                            String.Compare(, "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,;
                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
  • 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 500 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

785 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