关键注释不起作用

Key annotation not working

我收到以下错误:

Error 1 The type or namespace name 'keyAttribute' could not be found (are you missing a using directive or an assembly reference?)

enter code here

c:\users\hp\documents\visual studio 2013\Projects\ProductApps\ProductApps\Models\Product.cs 13 10 ProductApps

我的代码:

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;


namespace ProductApps.Models
{
    public class Product
    {
        [key]
        public int Id { get; set; }
        public string ProductName { get; set; }
        public string Price { get; set; }
        public string Description { get; set; }
    }
}

有谁能告诉我为什么会出现错误以及如何解决它?

请加

using System.ComponentModel.DataAnnotations;

你的 using 语句并尝试(大写 K)

[Key]
public int Id { get; set; }

您的项目中是否引用了 System.ComponentModel.Annotations.dll 程序集?