Add new cloumn in databse using forward mapping

Thread is closed for posting
6 posts, 1 answers
  1. Ratndeep
    Ratndeep avatar
    40 posts
    Member since:
    Feb 2009

    Posted 30 Nov 2009 Link to this post

    I am new to OpenAccess and using forward mapping in my project.
    i have this class declared in Model :

     [Persistent(IdentityField = "id")]
        public class Currency : Entity
        {
            /********************************************************************
             * Database Fields
             * ******************************************************************/
            #region Database Fields
            private string code;
            private string symbol;
            #endregion

            /********************************************************************
             * Properties
             * ******************************************************************/
            #region Properties
            [FieldAlias("code")]
            public string Code
            {
                get { return code; }
                set { code = value; }
            }

            [FieldAlias("symbol")]
            public string Symbol
            {
                get { return symbol; }
                set { symbol = value; }
            }
    }
    Now  i want to  add two more properties here named currencyName and result . So how should i do it here so this column is also created in database side.

    Thanks in advance..
  2. Answer
    IT-Als
    IT-Als avatar
    381 posts
    Member since:
    Sep 2008

    Posted 30 Nov 2009 Link to this post

    Hi Ratndeep,

    You just add the corresponding fields (private....) and your public properties for reading/writing those fields and rebuild your project. This naturally assumes that you have the UpdateDatabase property on your project (see project properties) set to True.
    OpenAccess will then migrate your existing schema to the new one (eg. add two new columns in the table)

    You can use the Forward Mapping dialog (in the Telerik menu within Visual Studio) to define the column names and other properties if you want to.

    Regards

    Henrik
  3. Ratndeep
    Ratndeep avatar
    40 posts
    Member since:
    Feb 2009

    Posted 30 Nov 2009 Link to this post

    Thanks Henrik for this.
    Could u tell me how to declare a foriegn key in openAccess.
  4. IT-Als
    IT-Als avatar
    381 posts
    Member since:
    Sep 2008

    Posted 30 Nov 2009 Link to this post

    Hi,

    In the Forward mapping dialog, when you select a field in your persistent class there is a region called "Generate SQL foreign key constraint" that can be used for that purpose.

    Regards

    Henrik
  5. Ratndeep
    Ratndeep avatar
    40 posts
    Member since:
    Feb 2009

    Posted 30 Nov 2009 Link to this post

    Hi Henrik,

    There is a no option of "Generate SQL foreign key constraint" .I am using Telerik OpenAccess ORM 2009.3
  6. IT-Als
    IT-Als avatar
    381 posts
    Member since:
    Sep 2008

    Posted 30 Nov 2009 Link to this post

    Hi again,

    Oh sorry... Naturally this is only enabled if you have a reference to another persistent class or a list of persistent classes... like in the Order-OrderLine relationship for example. Then the foreign key constraint will be placed on the fk_orderid column in the OrderLine table, because that field denotes which OrderLine belongs to what Order. Please note that the Order-OrderLine is only mentioned as an example.

    Regards

    Henrik
Back to Top