MVC, Views and System.Data.Entity c# entity-framework


I have a Repository Project that is added to my MVC application.

Within my C# code, of the MVC Web App, I have had to add a reference to System.Data.Entity so that I can access the objects from my Repository.

So the following fails if I do not have the reference added;

DataRepository<Store> repo = new DataRepository<Store>();
List<Store> allSorted = repo.All(x =>;

Now I want to pass that list to my Partial View, which sits within a FVM and it's the FVM that I pass to the Partial View.

So the index.aspx code;

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<StoresFVM>" %>

<% Html.RenderPartial("StoreList", Model.StoreListFVM); %>

And the ASCX code;

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<StoreListFVM>" %>

    SelectList storeList = new SelectList(Model.Stores.Select(x => new { Value = x.number, Text = }),"Value","Text");

<%= Html.DropDownList("SelectedStore", storeList) %>

However, I get an error informing me that I need to include a reference to System.Data.Entity in the ascx. I don't get why for one.

I have tried adding the namespace to the web.config file and I have tried importing the namespace at the top of the ascx page.



\nasfile02\Visual Studio 2010\Projects\TOM\TOM\Views\Stores\PartialViews\StoreList.ascx(4): error CS0012: The type 'System.Data.Objects.DataClasses.EntityObject' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Entity, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'.


namespace TOM.FormViewModels
    public class StoresFVM
        public StoreListFVM StoreListFVM { get; set; }

namespace TOM.FormViewModels
    public class StoreListFVM
        public List<Store> Stores { get; set; }
3/10/2013 9:53:35 AM

Accepted Answer

You should make sure the web.config looks as following:

<compilation debug="true" targetFramework="4.0">
    <add assembly="System.Data.Entity, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

Also described at:

5/23/2017 12:32:36 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow