2

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?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
  • Have you checked the answer here? http://stackoverflow.com/questions/9164717/the-type-or-namespace-name-dataannotations-does-not-exist-in-the-namespace-sy – Farhad Jabiyev Apr 15 '14 at 08:36

1 Answers1

3

Solution explorer -> Add reference -> Select .Net tab -> select System.ComponentModel.DataAnnotations from the list

Sajeetharan
  • 216,225
  • 63
  • 350
  • 396