I’m sure that I’m missing something simple here.
I’m trying to follow a Code First Entity Framework tutorial which tells me to use some Data Annotations.
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; }
}
}
The compiler doesn’t have any issues with the first two annotations but it doesn’t seem to like: [Column(TypeName="image")].
Errors:
-
The type or namespace name ‘Column’ could not be found.
-
The type or namespace name ‘ColumnAttribute’ could not be found.
I’m using Visual Studio 2012 and Entity Frameworks 5.
Any suggestions?
In Entity Framework 4.3.1,
ColumnAttributeis defined inSystem.ComponentModel.DataAnnotationsnamspace , which is available inEntityFramework.dll. So if you have a reference to that dll and a using statement to the namespace, you should be fine.In Entity Framework 5, It is in
System.ComponentModel.DataAnnotations.Schemanamspace, So you need to add a reference to that in your class.You can read more detailed information about it here.