Foreign key

2 posts, 0 answers
  1. Jürgen
    Jürgen avatar
    11 posts
    Member since:
    Aug 2010

    Posted 15 Dec 2011 Link to this post

    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?

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

  2. Ivailo
    Ivailo avatar
    318 posts

    Posted 20 Dec 2011 Link to this post

    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.


    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!

Back to Top