Inserting record with autoinc column is always zero.

Posts   
 
    
ABOH
User
Posts: 148
Joined: 06-Sep-2011
# Posted on: 21-Oct-2011 03:40:29   

Hello,

We are using an Oracle database and are using Silverlight + RIA/DDS. We have an Accounts table that contains account information for our customers. The information in this table is common to all of our customers regardless of the Silverlight application that they are subscribed to use. Its primary key is a column named "AccountId". This column has an Oracle sequence attached to it so the values are automatically incremented on each insert.

For one of our subscription applications, there is a a subclass of Accounts named "EtraxAccounts". It contains information that is specific to that application such as whether it is available to the customer. This table has an AccountId field, which was inherited from the Accounts entity.

So, here is the question... Why won't the sequence assigned to the AccountId column in the Accounts table not automatically increment when inserting a new EtraxAccount record? If I insert a new record in Accounts using SQL in a command window, it properly increments. However, the inserted record using our DAL had an AccountId of 0 rather than 3 in the database tables.

Here is what I did...

I created a new EtraxAccount entity, placed values in the required fields, and inserted it into the EtraxAccount table through our domain data source method (shown below). It was successful, but the AccountId was zero rather than the next value in the AccountId sequence in the Accounts table (parent to the EtraxAccount table, see attached pictures).

I would appreciate your help sorting out this issue... We definitely believe that using subclasses is a great way to partition our application specific data, so this question is very important to us.

Thank you for your help and time!

Mike

-------------------- DomainDataSource Insert Method ------------ [Insert] public void InsertEtraxAccount(EtraxAccountEntity theEtraxAccount) { var adapter = new DataAccessAdapter(); theEtraxAccount.IsNew = true; // Indicate that it is new adapter.SaveEntity(theEtraxAccount); //adapter.Commit();

}

---------------- BASIC DATABASE STRUCTURE -------------- Account (abstract) AccountId (primary key, autoincremented via Oracle sequence on inserts) AccountLabel (unique name presented to users when they want to select an account) Address City . . .

EtraxAccount (subclass of Account) AccountId (inherited from Account, primary key) AnotherField (a field that is specific to an EtraxAccount. . .

.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 21-Oct-2011 07:33:33   

(no image attached)

Did you specify the Sequence at the field mapping tab in LLBLGen Designer?

David Elizondo | LLBLGen Support Team
ABOH
User
Posts: 148
Joined: 06-Sep-2011
# Posted on: 22-Oct-2011 02:53:00   

Hi Daelmo,

Thank you for your quick response! Based on the information that you provided, I added the sequence to the primary key in the parent entity and inserted a record, but I was still getting zero in the PK field. I did a little research on the adapter and changed my adapter code to refetchaftersave. After making this change, inserting a record in the parent entity worked properly. Next, I changed the adapter code in the DDS for the subtype, EtraxAccountEntity, and inserted a record into it... Et voila! It had the proper AccountId! So, it looks like this issue is resolved for us. Yea!

Thank you for your help,

Mike

ABOH
User
Posts: 148
Joined: 06-Sep-2011
# Posted on: 22-Oct-2011 02:54:00   

In case someone else has this issue, here is what I did with the adapter in our domain data source code... I added the 'true' parameter.

adapter.SaveEntity(theEtraxAccount, true);