【发布时间】:2012-12-11 23:21:33
【问题描述】:
我刚开始研究 WebMatrix,我学习了 this 教程来学习基础知识,然后我从 this 开始学习 WebMatrix 上的实体框架(注意:该教程适用于 WebMatrix 1,但我看到的唯一改变是您将帮助程序安装到项目中的方式)。问题是,我安装了 Entity Framework 帮助程序,但我的项目无法识别 EntityFramework.dll。
我收到此错误The type or namespace name 'MaxLength' could not be found (are you missing a using directive or an assembly reference?)。但是 EntityFramework.dll 确实出现在我的 bin 文件夹中,这是怎么回事?我不明白为什么引用不起作用。
这是我根据第二个教程和安装 EntityFramework 助手后的 Web.config 文件:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<system.web>
<compilation debug="true" targetFramework="4.0"><assemblies><add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /><add assembly="System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /></assemblies></compilation>
</system.web>
<connectionStrings>
<add name="BookContext" connectionString="Data Source=|DataDirectory|Books.sdf" providerName="System.Data.SqlServerCe.4.0" />
</connectionStrings>
</configuration>
这是编译器输出link
我错过了什么吗?为什么我的项目无法正确识别 EntityFramework.dll?
更新
当我从 Visual Studio 2012 中创建的网页项目中复制 EntityFramework.dll 时,我认为问题已解决,但即使不再显示错误,WebMatrix 仍然无法识别 Table、Column、ForeignKey 等注释, 逆属性等。
我真的不明白,创建了一个简单的数据库,但我不能使用 EntityFramework 注释来指定数据库所需的所有内容。 WebMatrix 应该识别 EntityFramewor.dll 但它不是。我需要帮助,因为我真的迷路了。
【问题讨论】:
-
MaxLengthAttribute 位于 System.ComponentModel.DataAnnotations.dll 程序集中。 msdn.microsoft.com/en-us/library/…
-
实体框架也有一个 MaxLengthAttribute msdn.microsoft.com/en-us/library/…
-
是的,它曾经存在于 EntityFramework 中,但后来被移至 System.ComponentModel.DataAnnotations
-
那么像 Table、Column、InverseProperty 之类的注释呢,我正在尝试使用这些注释生成数据库,但即使它们来自它们所在的 EntityFramework,它们也无法识别System.ComponentModel.DataAnnotations 命名空间,我不明白为什么微软决定这样做。除了 EntityFramework,我还有什么其他选择?
-
我应该将 using 指令
using System.ComponentModel.DataAnnotations.Schema;添加到您的页面中。
标签: entity-framework dll webpage webmatrix