Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The type or namespace name 'Column' could not be found

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?

like image 304
Arcadian Avatar asked Oct 06 '12 09:10

Arcadian


2 Answers

In Entity Framework 4.3.1, ColumnAttribute is defined in System.ComponentModel.DataAnnotations namspace , which is available in EntityFramework.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.Schema namspace, So you need to add a reference to that in your class.

using System.ComponentModel.DataAnnotations.Schema;

You can read more detailed information about it here.

like image 161
Shyju Avatar answered Oct 15 '22 22:10

Shyju


I had the correct using statements ...

I had this problem despite having the correct using statements.

In my case, my project was generated by dotPeek after decompiling a dll (the original source code was lost).

dotPeek created the project with a reference to a copy of EntityFramework.dll just sitting in some folder, not being managed by NuGet.

What worked for me was to remove the reference to EntityFramework, and re-add it using the NuGet console.

like image 26
Walter Stabosz Avatar answered Oct 15 '22 22:10

Walter Stabosz