This is a migrated thread and some comments may be shown as answers.
Set default value and foriegn key
2 Answers 29 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ratndeep
Top achievements
Rank 1
Ratndeep asked on 30 Nov 2009, 01:14 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Damyan Bogoev
Telerik team
answered on 02 Dec 2009, 02:24 PM
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.
0
Ratndeep
Top achievements
Rank 1
answered on 04 Dec 2009, 05:47 AM
Thanks Damyan Bogoev .
Its really useful for me..
Tags
General Discussions
Asked by
Ratndeep
Top achievements
Rank 1
Answers by
Damyan Bogoev
Telerik team
Ratndeep
Top achievements
Rank 1
Share this question
or