Print Page | Close Window

Assigning value to key field in table

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=756
Printed Date: 07-Apr-2025 at 12:38am


Topic: Assigning value to key field in table
Posted By: BillG
Subject: Assigning value to key field in table
Date Posted: 06-Apr-2008 at 8:51pm
First off I don't have a choice about the structure of these tables because I am programming against a database used by other apps.  I have two tables that are related.
 
Event - Primary Key EventId
 
EventStep which is a child of Event and has the EventId + StepID as the Primary Key and a foreign key of EventId back to the parent. 
 
When I create the Event record, I want to retrieve the next value from a table which holds the next EventID.
 
When the step is created I want to do the following.
 

public static EventStep Create(PersistenceManager pManager, Int32 eventId, Int32 stepId)

{

EventStep aEventStep = pManager.CreateEntity<EventStep>();

aEventStep.EventID = eventId;

aEventStep.EventStepID = stepId;

aEventStep.TSCreated = DateTime.Today;

aEventStep.DateOccured = DateTime.Today;

pManager.AddToManager();

return aEventStep;

}

It tells me that I can't do this because EventId and EventStepId are read-only fields.  How do I get around this, other than changing the database which isn't an option at this point in time.

Bill



Replies:
Posted By: BillG
Date Posted: 07-Apr-2008 at 1:01pm
forget it.  I solved it.
 
aEventStep["EventID"] = eventId;
aEventStep["EventStepId"] = stepId;
 
 
Bill
 



Print Page | Close Window