problem with generated insert query

Posts   
 
    
Posts: 13
Joined: 15-Jan-2006
# Posted on: 07-May-2006 06:20:26   

Hello,

I'm having trouble while saving an entity. For, some reasons, the INSERT query being generated only contains the foriegn key values. Here's an example of my code:


OrderEntity order = new OrderEntity();

order.Paid = true;
order.Subtotal = 25.36;
order.BuyerID = 25;

(several other values being set)

DataAccessAdapter adapter = new DataAccessAdapter();
adapter.SaveEntity(order, true, true);

This throws an error because the Subtotal field is not part of the INSERT query and it is not a nullable field. There are several other fields that are not part of the query. Here is the query that I obtained from the QueryExecuted property of the exception:


INSERT INTO [WIACAM].[dbo].[Order] ([SellerID], [StoreID], [BuyerID], [BillingInformationID], [ShippingContactInformationID], [SalesChannelID], [InstanceID]) VALUES (@SellerID, @StoreID, @BuyerID, @BillingInformationID, @ShipAddressID, @SalesChannelID, @InstanceID)

You'll notice that only ID (foreign key) fields are included in the query. There are several other non-foreign key values that should be a part of this query. Has anyone else seen this problem? What am I doing wrong? I haven't had this issue with any of my other entities.

Thanks, Jason Hodges

Rogelio
User
Posts: 221
Joined: 29-Mar-2005
# Posted on: 07-May-2006 13:44:18   

Hi,

Are creating the OrderEntity only once and trying to reutilize the object?

Posts: 13
Joined: 15-Jan-2006
# Posted on: 07-May-2006 14:36:56   

Yes, I am creating the OrderEntity object and passing it between pages. I only persist it to the database on one particular page. Is there a problem with this approach?

Rogelio
User
Posts: 221
Joined: 29-Mar-2005
# Posted on: 07-May-2006 15:26:43   

austinHodge wrote:

Yes, I am creating the OrderEntity object and passing it between pages. I only persist it to the database on one particular page. Is there a problem with this approach?

There is not problem if the OrderEntity is created each time that you need to persist a new Oorder; but if you are creating only one OrderEntity and trying to persist it many times setting the fields.State = New each time that you need to persist a new Order, then that is your problem, to reuse the object set the field's Changed property to true. This is necesary because if you are assigning to a field the same value the field has at the time of the assigning then the field is not marked as changed and not persisted.

Posts: 13
Joined: 15-Jan-2006
# Posted on: 07-May-2006 16:04:16   

Ok, thank you very much for your help! I can save my order now...

Rogelio
User
Posts: 221
Joined: 29-Mar-2005
# Posted on: 07-May-2006 16:19:19   

You are welcome.