找不到类型或命名空间名称“列”

时间:2012-10-06 09:49:01

标签: c# .net entity-framework ef-code-first

我确信我在这里缺少一些简单的东西。 我正在尝试遵循Code First Entity Framework教程,该教程告诉我使用一些数据注释。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;

namespace Model
{
    public class Destination
    {
        public int DestinationId { get; set; }

        [Required]
        public string Name { get; set; }
        public string Country { get; set; }
        [MaxLength(500)]
        public string Description { get; set; }

        [Column(TypeName="image")]
        public byte Photo { get; set; }

        public List<Lodging> Lodgings { get; set; }
    }
}

编译器对前两个注释没有任何问题,但它似乎不喜欢:[Column(TypeName="image")]

错误:

  • 找不到类型或命名空间名称“列”。

  • 找不到类型或命名空间名称“ColumnAttribute”。

我正在使用Visual Studio 2012和Entity Frameworks 5。

有什么建议吗?

2 个答案:

答案 0 :(得分:27)

Entity Framework 4.3.1 中,ColumnAttributeSystem.ComponentModel.DataAnnotations namspace中定义,EntityFramework.dll中提供了System.ComponentModel.DataAnnotations.Schema。因此,如果您对该命名空间有一个引用和对命名空间的using语句,那么您应该没问题。

实体框架5 中,它位于using System.ComponentModel.DataAnnotations.Schema; namspace中,因此您需要在类中添加对该内容的引用。

{{1}}

您可以阅读有关它的更多详细信息here

答案 1 :(得分:0)

我有正确的using条语句...

尽管有正确的using语句,但我还是遇到了这个问题。

以我为例,我的项目是由dotPeek在反编译dll后生成的(原始源代码丢失了)。

dotPeek创建的项目引用了EntityFramework.dll的副本,该副本仅位于某个文件夹中,不受NuGet的管理。

对我有用的是删除对EntityFramework的引用,然后使用NuGet控制台重新添加它。

相关问题