Error with Identity + Update

Posts   
 
    
Posts: 7
Joined: 17-May-2006
# Posted on: 17-May-2006 01:43:11   

From the doc's I tried to use the following via Self-Servicing and got the message: "The field ContainerId is read-only and can't be changed"

From the doc's the code below should work My Code: ContainerEntity ce = new ContainerEntity(); ce.ContainerId = 1; ce.IsNew = false; ce.UniqueId = _UniqueId; ce.Save();

Documentation Code: // [C#] CustomerEntity customer = new CustomerEntity(); customer.CustomerID="CHOPS"; customer.IsNew=false; customer.Phone = "(605)555-4321"; customer.Save();

Any thoughts?

Thanks

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 17-May-2006 02:55:02   

ContainerId field being an identity can't be updated and would be marked as read only in the designer. You could do this instead.

ContainerEntity ce = new ContainerEntity(1);
ce.UniqueId = _UniqueId;
ce.Save();
Posts: 7
Joined: 17-May-2006
# Posted on: 17-May-2006 13:42:32   

Right, but that causes a fetch, which I don't want. Thanks.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 17-May-2006 15:01:09   

The following Note was copied from the LLBLGen Pro documentation "Using the generated code -> SelfServicing -> Using the entity classes -> Modifying an Entity"

If you want to set an identity primary key column, you'll notice you can't do that because it is marked as read-only. Use the method entityObject.Fields[fieldindex or fieldname].ForcedCurrentValueWrite(value). See the reference manual for details about this method (EntityField.ForcedCurrentValueWrite).

Posts: 7
Joined: 17-May-2006
# Posted on: 17-May-2006 17:27:27   

Oops, stopped reading after it didn't work flushed

Will that force an identity_insert or does that just allow me to reference the field as the key? I'm not wanting to update the key, just use it as the identifier iin the update.

Thanks!

Posts: 7
Joined: 17-May-2006
# Posted on: 17-May-2006 17:46:21   

Never mind, found the info in the reference docs. Thanks for the heads up.

Posts: 7
Joined: 17-May-2006
# Posted on: 17-May-2006 23:31:57   

No joy:

Here's the SQL that's being executed: declare @P1 int set @P1=NULL exec sp_executesql N'INSERT INTO [dbo].[Container] ([ProcessCodeId]) VALUES (@ProcessCodeId);SELECT @ContainerId=SCOPE_IDENTITY()', N'@ContainerId int output,@ProcessCodeId int', @ContainerId = @P1 output, @ProcessCodeId = 24 select @P1

Here the setup for LLBL... ContainerEntity ce = new ContainerEntity(); ce.Fields["ContainerId"].ForcedCurrentValueWrite(Convert.ToInt32(aNode.Tag)); ce.ProcessCodeId = (int)grdMain.Selected.Rows[0].Cells["ProcessCodeId"].Value; ce.Save();

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 18-May-2006 03:11:37   

try this

ContainerEntity ce = new ContainerEntity();
ce.Fields["ContainerId"].ForcedCurrentValueWrite(Convert.ToInt32(aNode.Tag));
ce.ProcessCodeId = (int)grdMain.Selected.Rows[0].Cells["ProcessCodeId"].Value;
ce.IsNew = false;
ce.Save();

Posts: 7
Joined: 17-May-2006
# Posted on: 18-May-2006 13:31:24   

Worked like a champ! Thanks bclubb.