locked
What does it mean [Table]? RRS feed

  • Question

  • [Table("OfficerCheckinLog")]
        public class OfficerCheckin : IComparable
        {
            [Required]
            [Column("pkey")]
            [Key]
            public long CheckinID { get; set; }
            [Required]
            
            public int CompareTo(object obj)
            {
    	    // blah
            }
            // blah
         }
    Thanks
    Monday, November 5, 2012 8:47 PM

Answers

  • Hi ardmore;

    The class looks to be a Linq to Entity Framework Code First entity. The [Table("OfficerCheckinLog")] is Data Annotation It tells the Entity Framework that the class OfficerCheckin maps to a table in the database called OfficerCheckinLog. Without this Data Annotation / Attribute the class would map to a table in the database with the name OfficerCheckins. The other Data Annotation / Attribute do similar functions. For example Required means that the field is required field, Key means that the field is the Primary Key and Column means that the class property CheckinID is mapped to the column in the database called pkey.

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by ardmore Tuesday, November 6, 2012 1:06 PM
    Tuesday, November 6, 2012 3:31 AM

All replies

  • That's an Attribute.  It's simply providing information about that class/method/property/whatever that is accessible at runtime via reflection.  From the point of view of C# itself it does nothing, but certain frameworks, functions, etc. can potentially utilize attributes to do...whatever they want.  You can't really find any documentation on any attribute itself, you need to figure out what you're doing with this object that uses the attributes; the documentation for that will [hopefully] specify what attributes should be used and what they do.
    • Edited by servy42 Monday, November 5, 2012 9:56 PM
    Monday, November 5, 2012 9:54 PM
  • To add to what servy said, I believe that particular attribute (along with the attributes on the properties) are Linq to SQL mapping attributes.  They are for ORM mapping to your database.
    Monday, November 5, 2012 9:58 PM
  • Hi ardmore;

    The class looks to be a Linq to Entity Framework Code First entity. The [Table("OfficerCheckinLog")] is Data Annotation It tells the Entity Framework that the class OfficerCheckin maps to a table in the database called OfficerCheckinLog. Without this Data Annotation / Attribute the class would map to a table in the database with the name OfficerCheckins. The other Data Annotation / Attribute do similar functions. For example Required means that the field is required field, Key means that the field is the Primary Key and Column means that the class property CheckinID is mapped to the column in the database called pkey.

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by ardmore Tuesday, November 6, 2012 1:06 PM
    Tuesday, November 6, 2012 3:31 AM
  • Hi,

    I thing your answer lies in these links

    What are attributes > http://msdn.microsoft.com/en-us/library/5x6cd29c.aspx

    also see link below

    http://msdn.microsoft.com/en-us/library/84c42s56.aspx < this link describes custom attributes, once you understand this you will get to know about built in attributes



    Please mark as answer is you find it helpful. Thanks Deepak Kalra

    • Proposed as answer by Deepak Kalra Tuesday, November 6, 2012 6:48 AM
    Tuesday, November 6, 2012 6:48 AM