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

question on database with constraint

1 Answer 83 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
alain
Top achievements
Rank 1
alain asked on 29 Jan 2011, 02:40 PM

hi, first time here..
 i have a project with sqlserver database but no reference foreign key. So now i have changed my project to add the constraint of reference with foreign key to the database tables as below:. e.g.

 ALTER TABLE Staffs

 Add CONSTRAINT fk_Staffs FOREIGN KEY(UserId) REFERENCES Users(Id);

 

But i don see the benefit after i added the foreign key.. the tables are all linked up now in my .dbml but when i try to write this..

this.Users.Staff , the staff is always null ... do i still have to initialize that staff eventhough all tables are already linked up?

In my Users.cs form,
1) Do i still have to declare  public Staff Staff { get; set; } in Users class?
2) Do i have to initialize the this.Staff in OnCreated? 

Also partial void OnCreated()
        {
            this.Staff = new Staff();
            //this.CourseTutor = new CourseByTutor();
           // this.CourseUserStatus = new CourseUserStatuse();
           
            //this.Payment = new Payment();
            //this.Payment.SaleOrderItem = new SaleOrderItem();
            //this.Payment.SaleOrderItem.SaleOrder = new SaleOrder();
            //  this.SaleOrder = new SaleOrder();
        }

All the commented code are written previously before i add reference foreignkey..so after i add the reference foreign key, do i still need that?

1 Answer, 1 is accepted

Sort by
0
Damyan Bogoev
Telerik team
answered on 03 Feb 2011, 09:44 AM
Hello alain,

I was unable to reproduce this behavior with Telerik OpenAccess ORM and it seems that you are using a Linq to Sql model (.dbml file). In this case maybe you should contact the Microsoft Support regarding the issues you are facing, they should be able to help you.

Greetings,
Damyan Bogoev
the Telerik team
Accelerate your learning with industry's first Telerik OpenAccess ORM SDK. Download today.
Tags
LINQ (LINQ specific questions)
Asked by
alain
Top achievements
Rank 1
Answers by
Damyan Bogoev
Telerik team
Share this question
or