Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为EF模型使用ColumnAttribute时出错_C#_Asp.net_Entity Framework_Webmatrix_Asp.net Webpages - Fatal编程技术网

C# 为EF模型使用ColumnAttribute时出错

C# 为EF模型使用ColumnAttribute时出错,c#,asp.net,entity-framework,webmatrix,asp.net-webpages,C#,Asp.net,Entity Framework,Webmatrix,Asp.net Webpages,我已经用实体框架扩展了我的ASP.Net网页应用程序,我已经通过NuGet在Visual Studio中下载了实体框架。现在,我在尝试为属性指定不同的列名时出现以下错误 CS0246:找不到类型或命名空间名称“列”(是 是否缺少using指令或程序集引用?) 我的模型: using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; using System.L

我已经用实体框架扩展了我的ASP.Net网页应用程序,我已经通过NuGet在Visual Studio中下载了实体框架。现在,我在尝试为属性指定不同的列名时出现以下错误

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
中,所以我无法理解这个问题

更新 我的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>

在实体框架5中,ColumnAttribute类被移动到另一个名为System.ComponentModel.DataAnnotations.Schema的命名空间中。因此,如果您使用的是EF5,那么您需要添加一个using语句,以便在您的模型类中也包含该名称空间

 using System.ComponentModel.DataAnnotations;
 using System.ComponentModel.DataAnnotations.Schema;

在实体框架5中,ColumnAttribute类被移动到另一个名为System.ComponentModel.DataAnnotations.Schema的命名空间中。因此,如果您使用的是EF5,那么您需要添加一个using语句,以便在您的模型类中也包含该名称空间

 using System.ComponentModel.DataAnnotations;
 using System.ComponentModel.DataAnnotations.Schema;


在将我的应用程序升级到.NET4.5之后,它终于可以按预期工作了。看起来EF 5与.Net 4.0不完全兼容。

在将我的应用程序升级到.Net 4.5后,它终于可以正常工作了。看起来EF 5与.Net 4.0不完全兼容。

该属性位于System.ComponentModel.DataAnnotations下。我认为这取决于他使用的EF版本,它以前住在那里,但现在在System.ComponentModel.DataAnnotations.Shema中(我认为从EF 5开始)。我会检查你的目标是.NET4.5,并且正在引用EF的最新版本。我刚刚意识到,即使NuGet告诉我不是这样,我还是安装了EF4.4而不是EF5。请看一下我的Web.Config。这可能是问题所在吗?该属性位于System.ComponentModel.DataAnnotations下。我认为这取决于他使用的EF版本,它以前位于其中,但现在位于System.ComponentModel.DataAnnotations.Shema中(我认为从EF 5开始)。我会检查你的目标是.NET4.5,并且正在引用EF的最新版本。我刚刚意识到,即使NuGet告诉我不是这样,我还是安装了EF4.4而不是EF5。请看一下我的Web.Config。这可能是问题所在吗?正如您在我的代码中看到的,我已经做到了。但是我刚刚发现我可能安装了错误的EF版本。这可能是问题所在吗?我刚试过,但没用。在mypackages.config中,我发现了以下内容:
现在安装的是什么版本?4.4还是5?我不明白…它的版本5。。从控制台PM>安装程序包EntityFramework尝试此命令-版本5.0.0
“EntityFramework 5.0.0”已安装。已成功将“EntityFramework 5.0.0”添加到Pezag.Net。
但仍不起作用。某些功能仅在编写针对.Net 4.5的应用程序时可用。这包括枚举支持、空间数据类型、表值函数和性能改进。但是我刚刚发现我可能安装了错误的EF版本。这可能是问题所在吗?我刚试过,但没用。在mypackages.config中,我发现了以下内容:
现在安装的是什么版本?4.4还是5?我不明白…它的版本5。。从控制台PM>安装程序包EntityFramework尝试此命令-版本5.0.0
“EntityFramework 5.0.0”已安装。已成功将“EntityFramework 5.0.0”添加到Pezag.Net。
但仍不起作用。某些功能仅在编写针对.Net 4.5的应用程序时可用。这包括枚举支持、空间数据类型、表值函数和性能改进。