This is a migrated thread and some comments may be shown as answers.

Foreign key

1 Answer 60 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jürgen
Top achievements
Rank 1
Jürgen asked on 15 Dec 2011, 04:24 PM

Hello Telerik team!

I have 2 entities: Test and Person. Test-table must have reference to Person-table (foreign key)

As I understand foreign key will be added if I add to object Test - link to object Person. But in this case on load Test from database - will be loaded full Person from database too?? But in this case I need only Nr Person. Should I have FetchPlan?

Now I have some FetchPlan for Person-entity for loading general data like Nr, FirstName, DateOfBirth. But on Load Test I need load only PersonNr. Another words - I don't want use object Person in Test. I want work only with int property, which is marked as ForeignKey. Can I do it?

[Persistent]
public class Test
{
  public int Date {get; set;}
  // this
  public int PersonNr {get; set;}
  // instead this
  public Person Person_ {get; set;}
}
  
[Persistent]
public class Person
{
  public int Nr {get; set;} // PK
  public string FirstName {get; set;}
  public string Name {get; set;}
  // .....
}

1 Answer, 1 is accepted

Sort by
0
Ivailo
Telerik team
answered on 20 Dec 2011, 02:57 PM
Hello Jürgen,

You don't have to worry about that - when you read the Test from the database, due to the default behavior of lazy loading, the Person will not be loaded automatically, unless you require it explicitly. You can even choose which columns would you like to be loaded - as explained in this article.

Give it a try and do not hesitate to get back to us if there are any problems.


Greetings,

Ivailo
the Telerik team

Q3’11 of Telerik OpenAccess ORM is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

Tags
General Discussions
Asked by
Jürgen
Top achievements
Rank 1
Answers by
Ivailo
Telerik team
Share this question
or