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

.net c# ef-code-first entity-framework

Question

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?

1
15
10/6/2012 9:49:00 AM

Accepted Answer

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.

31
11/7/2015 7:30:02 PM

Popular Answer

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.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow