Set default value and foriegn key

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

    Posted 30 Nov 2009 Link to this post

    Hi All,
    I am using forward mapping.I have to declare a foreign key in one of my class.How can i do this and also how can i set default value for a filed?

    Thanks.
  2. Answer
    Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 02 Dec 2009 Link to this post

    Hi Ratndeep,

    You could use the following approach in order to declare a foreign key in one of your classes during the forward mapping:
    1.    Inside the class declare a reference to the other class as well as the foreign key:

    public class ClassOne
    {
        ...
         
        private int id;
     
        public int Id
        {
            get { return id; }
            set { id = value; }
        }
     
        ...
    }
     
    public class ClassTwo
    {
        ...
         
        private int id;
     
        public int Id
        {
            get { return id; }
            set { id = value; }
        }
     
        private ClassOne classOne;
     
        public ClassOne ClassOne
        {
            get { return classOne; }
            set { classOne = value; }
        }
     
        private int classOneId;
     
        public int ClassOneId
        {
            get { return classOneId; }
            set { classOneId = value; }
        }
         
        ...
    }

    2.    When you finish with the settings inside the Forward Mapping wizard open the App.config file
    3.    You should map the classOne and the classOneId fields to one and the same column inside the App.config:

    ...
    <field name="classOne" null-value="exception">
      <extension key="db-constraint" value="ClassOneId" />
      <extension key="db-column">
        <extension key="db-column-name" value="ClassOneId" />
      </extension>
    </field>
    <field name="classOneId" null-value="exception">
      <extension key="db-column">
        <extension key="db-column-name" value="ClassOneId" />
      </extension>
    </field>
    ...

    Additional information about mapping fields to the same columns can be found here.
    I hope the provided information will be helpful for you.

    Best wishes,
    Damyan Bogoev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Ratndeep
    Ratndeep avatar
    40 posts
    Member since:
    Feb 2009

    Posted 03 Dec 2009 Link to this post

    Thanks Damyan Bogoev .
    Its really useful for me..
Back to Top