Does Subsonic use optimistic concurrency in some way?
Best Answer
If by use you mean built-in to SubSonic, then no. Optimistic concurrency can however be achieved with SubSonic reasonably simply.
Assuming that you are using SQL Server (if not I'll let you translate the following instructions into a solution that works on your database provider) this is one way to go:
Include a column of type timestamp on each table you wish to ensure concurrency.
CREATE TABLE Product
(
ProductID int NOT NULL IDENTITY(1,1),
Name varchar(256) NOT NULL,
RowStamp timestamp /* This will hold a timestamp for the table */
)
Read the value of the timestamp along with the data so that you can use it later to compare.
var product = new SubSonic.Select()
.From<Product>()
.Where(Product.ProductIDColumn).IsEqualTo(productId)
.ExecuteSingle<Product>();
var rowStamp = product.RowStamp;
// ... Show a form to the user with the data from the product
When performing an UPDATE compare the value of the the timestamp to the database value. If the timestamp doesn't match, the row has been modified and the user can be notified of the situation (or you can handle it however you like)
// ... After retrieving the values from the form
var result = new SubSonic.Update(Product.TableSchema)
.Set(Product.NameColumn).Equal(newName)
.Where(Product.ProductIDColumn).IsEqualTo(productId)
.And(Product.RowStamp).IsEqualTo(rowStamp)
.Execute();
if (result != 1)
{
// Notify the user there may be a problem
}
I never had any problems with class generation with SubSonic. Are you sure your schema is a good one? Do you follow the conventions? If some tables are not generated, you may be missing PKs, but if you look into the generated classes it will tell you (in a comment) that this is the case. That's all the advice that I can give based on the information provided by you. I still think it's not SubSonic that's the problem...
Best Answer
If by use you mean built-in to SubSonic, then no. Optimistic concurrency can however be achieved with SubSonic reasonably simply.
Assuming that you are using SQL Server (if not I'll let you translate the following instructions into a solution that works on your database provider) this is one way to go:
Include a column of type
timestamp
on each table you wish to ensure concurrency.Read the value of the timestamp along with the data so that you can use it later to compare.
When performing an
UPDATE
compare the value of the the timestamp to the database value. If the timestamp doesn't match, the row has been modified and the user can be notified of the situation (or you can handle it however you like)