我已经使用Entity Framework扩展了我的ASP.Net Web Pages应用程序,该应用程序框架是通过NuGet在Visual Studio中下载的。现在我得到以下错误,同时尝试为属性分配不同的列名称。为EF模型使用ColumnAttribute时出错
CS0246:类型或命名空间名称 '列' 找不到(被 你缺少using指令或程序集引用?)
我的模型:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
using WebMatrix.Data;
namespace Models {
public class News
{
public int Id { get; set; }
[Column("d_date")]
public DateTime Date { get; set; }
[Column("m_text")]
public string Text { get; set; }
}
}
ColumnAttribute
应该在System.ComponentModel.DataAnnotations.Schema
,所以我不明白这个问题。
UPDATE 我的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 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="MyDatasource" connectionString="server=localhost; database=testdb; User Id=***; Password=***;" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<customErrors mode="Off" />
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</assemblies>
</compilation>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>
</configuration>
该属性是在System.ComponentModel.DataAnnotations – 2013-04-29 16:19:23
我认为这取决于他使用的EF版本,它曾经住在那里但现在它在System.ComponentModel.DataAnnotations.Shema(EF 5 I认为)。我会检查你的目标是.NET 4.5,并引用最新版本的EF。 – blins 2013-04-29 16:32:17
我刚刚意识到,即使NuGet告诉我,否则,我已经安装了EF 4.4而不是EF 5.请看看我的Web.Config。这可能是问题吗? – android 2013-04-30 06:43:19