locked
Reading properties of DataMember RRS feed

  • Question

  • I'm trying, in Silverlight 4, to make tables in database based on DataMembers, i.e. by tutorial on http://stackoverflow.com/questions/47239/how-can-i-generate-database-tables-from-c-classes  I’m using DataMemebers to create sql query for tables.

    My question is: How can i check if certain DataMemeber is set as PrimaryKey and implement that in sql query?


    [Column(IsPrimaryKey = true)] //how to check if this is set

           [DataMember]

           public string UserName

           {

                    get { return _username; }

                    set { _ username = value; }

           }


    Or, how can i check what are DataAnnotations set for UserName further in code, for example:


            [Key,DataMember] //how to check what is set here
                public string UserName
                {
                    get { return _username; }
                    set { _username= value; }
                }

    Wednesday, June 22, 2011 6:26 AM

Answers

  • I don't think it is possible to check the value inside annotation.

    But you can add an additional field for example store the primary key name, then you can get which field is primary key.

    Monday, June 27, 2011 4:36 AM