简体   繁体   中英

System.ComponentModel.DataAnnotations was not found

I'm using Visual Studio 2010 . I'm reading . NET WebForms tutorial and trying to experimenting with Entities . As said in the Create Data Access layer I've pasted the following code in the just created class:

using System.ComponentModel.DataAnnotations;

namespace WingtipToys.Models
{
  public class Product
  {
    [ScaffoldColumn(false)]
    public int ProductID { get; set; }

    [Required, StringLength(100), Display(Name = "Name")]
    public string ProductName { get; set; }

    [Required, StringLength(10000), Display(Name = "Product Description"), DataType(DataType.MultilineText)]
    public string Description { get; set; }

    public string ImagePath { get; set; }

    [Display(Name = "Price")]
    public double? UnitPrice { get; set; }

    public int? CategoryID { get; set; }

    public virtual Category Category { get; set; }
  }
}

But I have an error discripted as

Error 1 The type or namespace name 'DataAnnotations' does not exist in the namespace 'System.ComponentModel' (are you missing an assembly reference?

How to fix this?

解决方案资源管理器->添加参考->选择.Net选项卡->从列表中选择System.ComponentModel.DataAnnotations

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM