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

Reference to foreign key not detected?

1 Answer 86 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.
Alec
Top achievements
Rank 1
Alec asked on 27 Feb 2009, 06:16 AM
I have these two classes: Company and Employee. A company has many employees.

public partial class Company  
    {  
          
        //The 'no-args' constructor required by OpenAccess.   
        public Company()  
        {  
        }  
 
        [Telerik.OpenAccess.FieldAlias("companyID")]  
        public int ID  
        {  
            get { return companyID; }  
            set { this.companyID = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("address")]  
        public string Address  
        {  
            get { return address; }  
            set { this.address = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("email")]  
        public string Email  
        {  
            get { return email; }  
            set { this.email = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("fax")]  
        public string Fax  
        {  
            get { return fax; }  
            set { this.fax = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("logo")]  
        public string Logo  
        {  
            get { return logo; }  
            set { this.logo = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("phone")]  
        public string Phone  
        {  
            get { return phone; }  
            set { this.phone = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("postalAddress")]  
        public string PostalAddress  
        {  
            get { return postalAddress; }  
            set { this.postalAddress = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("subDomain")]  
        public string SubDomain  
        {  
            get { return subDomain; }  
            set { this.subDomain = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("teleMallID")]  
        public int? TeleMallID  
        {  
            get { return teleMallID; }  
            set { this.teleMallID = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("webSite")]  
        public string WebSite  
        {  
            get { return webSite; }  
            set { this.webSite = value; }  
        }  
 
 
    } 


// Generated by Telerik OpenAccess  
    // Used template: c:\program files\telerik\openaccess orm\sdk\IDEIntegrations\templates\PCClassGeneration\cs\templates\classgen\class\partialdesignerdefault.vm  
    [Telerik.OpenAccess.Persistent(IdentityField="companyID")]  
    public partial class Company   
    {  
        private int companyID; // pk   
 
        private string address;  
 
        private string email;  
 
        private string fax;  
 
        private string logo;  
 
        private string phone;  
 
        private string postalAddress;  
 
        private string subDomain;  
 
        private int? teleMallID;  
 
        private string webSite;  
 
        private IList<EPYEmployee> employeeCol = new List<EPYEmployee>();  // inverse EPYEmployee.company  
 
 
          
 
          
    } 

public partial class EPYEmployee  
    {  
        //The 'no-args' constructor required by OpenAccess.   
        public EPYEmployee()  
        {  
        }  
 
        [Telerik.OpenAccess.FieldAlias("id")]  
        public int Id  
        {  
            get { return id; }  
            set { this.id = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("dAMProfileImageFK")]  
        public int? DAMProfileImageFK  
        {  
            get { return dAMProfileImageFK; }  
            set { this.dAMProfileImageFK = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("department")]  
        public string Department  
        {  
            get { return department; }  
            set { this.department = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("email")]  
        public string Email  
        {  
            get { return email; }  
            set { this.email = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("firstName")]  
        public string FirstName  
        {  
            get { return firstName; }  
            set { this.firstName = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("lastName")]  
        public string LastName  
        {  
            get { return lastName; }  
            set { this.lastName = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("mobile")]  
        public string Mobile  
        {  
            get { return mobile; }  
            set { this.mobile = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("password")]  
        public string Password  
        {  
            get { return password; }  
            set { this.password = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("phone")]  
        public string Phone  
        {  
            get { return phone; }  
            set { this.phone = value; }  
        }  
 
        [Telerik.OpenAccess.FieldAlias("title")]  
        public string Title  
        {  
            get { return title; }  
            set { this.title = value; }  
        }  
 
 
    } 

// Generated by Telerik OpenAccess  
    // Used template: c:\program files\telerik\openaccess orm\sdk\IDEIntegrations\templates\PCClassGeneration\cs\templates\classgen\class\partialdesignerdefault.vm  
    [Telerik.OpenAccess.Persistent(IdentityField="id")]  
    public partial class EPYEmployee   
    {  
        private int id; // pk   
 
        private int? dAMProfileImageFK;  
 
        private string department;  
 
        private string email;  
 
        private string firstName;  
 
        private string lastName;  
 
        private string mobile;  
 
        private string password;  
 
        private string phone;  
 
        private string title;  
 
        private Company company; // inverse Company.employeeCol  
 
 
          
 
          
    } 

In my database, I have an employee associated to company (id #2). But when I do this:

 //retrieve a row  
 Company companyitem = CompanyBO.GetCompanyById(2);  
              

the companyitem shown a list of zero employee.

Why is that? And also, why isn't the employee list get created as a property in the class generated?

1 Answer, 1 is accepted

Sort by
0
Jan Blessenohl
Telerik team
answered on 02 Mar 2009, 09:10 AM
Hello Alec,
Let's first discuss the reverse engineering process. You are not getting additional code generated in your part of the partial class. Only the OpenAccess part is regenerated. If you want all code generated from scratch you can delete the generated class files first. It is implemented in this way because we want to avoid to overwrite your code.

How do you detect that the employee collection is empty? Are you accessing the field or are you just looking inside the debugger?

The debugger can not do the lazy loading, because of that you will see a null collection before you access the field in your code. Please add the public property by hand and see the content in your application.

Kind regards,
Jan Blessenohl
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
General Discussions
Asked by
Alec
Top achievements
Rank 1
Answers by
Jan Blessenohl
Telerik team
Share this question
or