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

Problem with association insert

3 Answers 78 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.
Patrick
Top achievements
Rank 1
Patrick asked on 03 Mar 2011, 05:26 PM
Hi,

from the documentation 

Car newCar = new Car();
newCar.ABS = true;
newCar.AirConditioner = true;
newCar.ASR = true;
newCar.Available = false;
newCar.CarYear = 2012;
newCar.DVDPlayer = false;
newCar.Make = "Audi";
newCar.Model = "A8";
newCar.Mp3Player = true;
newCar.Navigation = false;
newCar.TagNumber = "PB 3341 SS";
Category newCategory = new Category();
newCategory.CategoryName = "MyCategory";
newCategory.Cars.Add(newCar);
dbContext.Add(newCategory);
dbContext.SaveChanges();

my code:

Print p = new Print();                         
p.LocationID = loc.ID;
p.Timestamp = DateTime.Now;
job.Prints.Add(p);

everything gets inserted into my database (sql 2005)
EXCEPT the JobID in my Print table. JobID is still null.
Is there something i need to set before SaveChanges?

thanks for help

UPDATE: Found the solutions some posts below. Thread can be closed

3 Answers, 1 is accepted

Sort by
0
gmendez
Top achievements
Rank 1
answered on 30 Sep 2011, 02:28 PM
Hi Patrick!! Would you point me to the post where you found the solution please?
Thanks!!

Gonzalo
0
Ivailo
Telerik team
answered on 05 Oct 2011, 01:41 PM
Hi Gonzalo,

The solution for this problem is setting the IsManaged property of the association to True - in Patrick's case that is the association between Job and Print Domain Classes.

For more information regarding IsManaged, it is described as a property and in the context of working with data (one-to-many relationships section) in our documentation.
 
Do not hesitate to contact us if you need further clarifications on this functionality.

Best wishes,
Ivailo
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's SQL Server Community Awards. We are competing in TWO categories and every vote counts! VOTE for Telerik NOW >>

0
gmendez
Top achievements
Rank 1
answered on 05 Oct 2011, 07:30 PM
Hi!!
That worked perfectly.
Thank you very much for your (as always) valuable help.
Regards,

Gonzalo
Tags
General Discussions
Asked by
Patrick
Top achievements
Rank 1
Answers by
gmendez
Top achievements
Rank 1
Ivailo
Telerik team
Share this question
or