Object properties aren't updated in portal method

Object properties aren't updated in portal method

Old forum URL: forums.lhotka.net/forums/t/9341.aspx


Doug Ramirez posted on Saturday, August 07, 2010

I have a very simple BusinessBase object that has an Id property that is set after a stored procedure is called to insert a row into a database table with an identity column.  The sproc returns the Id just fine, and when I step through the portal method I can see that the Id property is in fact being set.  But when the scope returns back to the code that calls the .Save method (in this case a unit test) the Id property is not longer set.

Here is the definition of the property:

private static PropertyInfo<int> IdProperty = RegisterProperty<int>(p => p.Id);

public int Id

{

get { return GetProperty(IdProperty); }

set { SetProperty(IdProperty, value); }

}


Here is the code that updates the property in the portal method:

[Transactional(TransactionalTypes.TransactionScope)]

protected override void DataPortal_Insert()

{

using (SqlConnection connection = Utilities.CreateConnection())

{

using (SqlCommand command = connection.CreateCommand())

{

connection.Open();

command.CommandType = CommandType.StoredProcedure;

command.CommandText = "InsertInvoice";

Id = Convert.ToInt32(command.ExecuteScalar());

}

}

}

 

Can anyone think of why this isn't working?  It must be something simple.  Also, no exceptions are being thrown.  Any help is greatly appreciated.

 

Lastly, I'm using CLSA 4.

Doug

Doug Ramirez replied on Saturday, August 07, 2010

Problem solved!  In short, my unit test had this:

invoice.Save();

but needed to have this:

invoice = invoice.Save();

In long, I've been using CLSA since the VB business objects days and took 2 years off from programming (yes, 2 years).  I just got back into it a month ago and my gawd have I forgotten a lot!
Sorry for the noise in the forum.
Doug

Copyright (c) Marimer LLC