Table Attribute not working with MVC5 and EF6 RRS feed

  • Question

  • Hello,

           Having an issue with a project I am working on.  I have a web project and portable classes.  I am using Entity Framework 6, and MVC 5.  Everything was working when I had all the classes in the Web side, but once I moved them to the Portable side, I began to have an issue with the data annotation.  Here is the code from one of the classes:

    namespace Inventory.Entities
        using System;
        using System.Collections.Generic;
        using System.ComponentModel.DataAnnotations;
        using System.ComponentModel.DataAnnotations.Schema;
        using System.Linq;
        public class Location
            public Location()
                Assets = new HashSet<Asset>();
            public int LocationID { get; set; }
            [Display(Name = "Location Name")]
            public string LocationName { get; set; }
            public virtual ICollection<Asset> Assets { get; set;}

    Now the issue is that Table has a red squiggle and I am getting the following error: Error  43  The type or namespace name 'TableAttribute' could not be found (are you missing a using directive or an assembly reference?)

    As far as I can tell everything is set up correctly, but this just does not want to work.  It is not only this class, but all of my classes.  The only reference I have in the portable classes is .Net with a target of 4.5.  Everything I read says this should work, but clearly it is not working.  I have also uninstalled and installed the entity framework, did a clean and build but with no luck.  Any thoughts?

    Michael R. Mastro II

    Tuesday, April 28, 2015 6:49 PM


  • Hello Michael,

    >>but once I moved them to the Portable side, I began to have an issue with the data annotation.

    This is by designed, please check the namespace “System.ComponentModel.DataAnnotations.Schema”: https://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.schema(v=vs.110).aspx, as you can see, only the DatabaseGeneratedAttribute is supported in Portable Class Library.(If a class is supported in PCL, there should be a  symbol).


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Fred Bao Thursday, May 7, 2015 2:29 AM
    Wednesday, April 29, 2015 8:30 AM