Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Parent and Child objects and foreign keys
Message
 
To
24/01/2007 04:09:12
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Environment versions
Environment:
VB 8.0
OS:
Windows Server 2003
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01188523
Message ID:
01188788
Views:
11
John,

>I am trying to save a parent (doctor) and child (address) object in one hit in such a way that the parent key is auto placed into the child object. I did the following
>
>In the address object i added the foreignkey assignment as follows
>
> Public Sub New()
> Me.TableName = "address"
> Me.PrimaryKey = ""
> Me.DefaultCommandType = CommandType.Text
> Me.ForeignParentKeyField = "parent_PK"
>
>then i added a property to doctor called address and registered it as a child object. Then I did the following code in my app test
>
> '' Now we have an address pk we can create DR
> Dim loDoctor As Doctor = New Doctor
> loDoctor.NewRow()
> loDoctor.Entity.First_name = "Erin"
> loDoctor.Entity.Last_Name = "Noonan"
> loDoctor.Entity.notify_emails = "sales@infotoday.com.au"
>
> '' Create new address first
> loDoctor.Address.NewRow()
> loDoctor.Address.Entity.post_code = "2060"
> loDoctor.Address.Entity.state = "NSW"
> loDoctor.Address.Entity.street = "Walker St"
> loDoctor.Address.Entity.street_no = "161"
> loDoctor.Address.Entity.suburb = "North Sydney"
> loDoctor.SaveRow()
>
>this created bith parent and child objects but did not assign the parent key. Am i missing something?

The assignment of the parent foreign key value occurs when the parent/child objects are saved. At that time when the parent primary key is generated (normally from a SQL Server Identity column) the value is propogated to all child/grandchild/etc objects.

Best Regards,
Kevin McNeish
Eight-Time .NET MVP
VFP and iOS Author, Speaker & Trainer
Oak Leaf Enterprises, Inc.
Chief Architect, MM Framework
http://www.oakleafsd.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform