MVC, Views and System.Data.Entity

本文关键字:Data Entity System and Views MVC | 更新日期: 2023-09-27 18:03:06

我有一个存储库项目,它被添加到我的MVC应用程序。

在我的c#代码中,MVC Web应用程序,我必须添加一个对System.Data.Entity的引用,以便我可以从我的存储库访问对象。

所以如果我没有添加引用,下面的操作就会失败;

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

现在我想把这个列表传递给我的局部视图,它位于FVM中,它是我传递给局部视图的FVM。

所以索引。aspx代码;

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<StoresFVM>" %>
<% Html.RenderPartial("StoreList", Model.StoreListFVM); %>

和ASCX代码;

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<StoreListFVM>" %>
<%        
    SelectList storeList = new SelectList(Model.Stores.Select(x => new { Value = x.number, Text = x.name }),"Value","Text");
%>
<%= Html.DropDownList("SelectedStore", storeList) %>

然而,我得到一个错误通知我,我需要在ascx中包含对System.Data.Entity的引用。我不明白为什么。

我已经尝试将命名空间添加到web。我已经尝试在ascx页面的顶部导入命名空间。

想法吗?

编辑

' nasfile02 ' Visual Studio2010年汤姆汤姆' ' ' Views ' '项目商店' PartialViews ' StoreList.ascx (4):错误CS0012:类型' system . data . objects . datacclasses . entityobject '在未引用的程序集中定义。你必须加上引用汇编的System.Data。= 4.0.0.0实体,版本,文化=中立,都必须要。

编辑

namespace TOM.FormViewModels
{
    public class StoresFVM
    {
        public StoreListFVM StoreListFVM { get; set; }
    }
}
namespace TOM.FormViewModels
{
    public class StoreListFVM
    {
        public List<Store> Stores { get; set; }
    }
}

MVC, Views and System.Data.Entity

你应该确保网页。配置如下:

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

详见:https://stackoverflow.com/a/3611040/1737862