I am using EF 5.0 Code First in my site and need help figuring out how to build the code for my insert. I have two entities (Euipment and EquipmentType) with a 1 to 1 relationship between the two on EquipmentTypeID. The insert I need help building is when
I add a new piece of equipment and a new EquipmentType at the same time. I.E. I just bought my first ImpactGun and it is my first AirTool so when I use the form on my web application I chose to add a new EquipmentType at the same time. This means that first
a new entiry in Type must be made and then that ID put into the Equipment table. Do I add the type, retreave the new ID into a variable, then add the new equipment or is there some way of doing it all in one whack?
Eagle_f90
Member
465 Points
531 Posts
Help needied builing EF 5.0 insert
Nov 26, 2012 08:06 PM|LINK
I am using EF 5.0 Code First in my site and need help figuring out how to build the code for my insert. I have two entities (Euipment and EquipmentType) with a 1 to 1 relationship between the two on EquipmentTypeID. The insert I need help building is when I add a new piece of equipment and a new EquipmentType at the same time. I.E. I just bought my first ImpactGun and it is my first AirTool so when I use the form on my web application I chose to add a new EquipmentType at the same time. This means that first a new entiry in Type must be made and then that ID put into the Equipment table. Do I add the type, retreave the new ID into a variable, then add the new equipment or is there some way of doing it all in one whack?
ignatandrei
All-Star
134511 Points
21576 Posts
Moderator
MVP
Re: Help needied builing EF 5.0 insert
Nov 27, 2012 03:37 AM|LINK
you can add in one move if you add a new EquipmentType and a new Equipment and put
<newEquipment>.EquipmentType = <new EquipmentType >
and then commit changes
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Help needied builing EF 5.0 insert
Nov 27, 2012 07:33 AM|LINK
Hi,
Can you show us your full codes and tell us what you have done?
Eagle_f90
Member
465 Points
531 Posts
Re: Help needied builing EF 5.0 insert
Nov 28, 2012 10:31 PM|LINK
Sorry I don't understand your notations. Do I not call the add on the new equipment type at all?
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Help needied builing EF 5.0 insert
Nov 29, 2012 12:17 AM|LINK
Yes, he means you can initialize a new instance to assign to EquipmentType.
@ignatandrei,
If I misunderstand what you mean, you can point it out on time;)
Reguards & Thanks