This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi In the manual you go through how transaction is being done. We are using a MySql database and from trying the TransactionScope, it does not work which is fine by us since Oracle might be the database later on. However, what is worse, I can't get the standard .NET transaction to work either with MySql. Here is some sample code I used:
The entity class being obvious and which works fine for saving data. However, the following code will still add the column "aaaa" into the code although the exception occurs since ThisDay is not set for the "bbbb" contribution object. Have I missed something? using (IDbTransaction transaction = Repository.BeginTransaction())
|
|
|
Hi Tobias, MySQL supports TransactionScope. Your code should look like: using (TransactionScope transactionScope = new TransactionScope()) Cheers, Andrew. |
|
|
Oh and MySQL supports DateTime fine too. |
|
|
Well, we might very well be swaping to an Oracle database later on so I would prefer to stay with the standard .NET transaction and not have to change this code. But you know what, as I left the office I realised I forgot to alter from the default MyISAM table type to InnoDB instead (see here for instance). And by doing this I discovered I don't even need to specify a transaction in the code for MySql since my code above roles back automatically. I reckon that this depends on that the @@autocommit is set to 1 as default. Since you are doing the inserts in a single batch to the database I reckon it ends up in the same transaction without me having to specify it directly. I'll see if I can confirm this by logging on the sql query that MySQL is actually is using. However, If I would keep the transaction in the code just for the future database switch sake, I'd have to write something like this to make it work: Contribution contribution = new Contribution(); ----------------- Another way of doing it is to move the CompleteUnitOfWork call into the end of the try block, after the SaveChanges method since this is where I get the MindScape ValidationException. Hmm. I just said it right there, didn't I? ValidationException would probably mean that the SQL queries is not even sent to the database since the domain model found the error first. So the Transaction is not even needed in this case since actual domain model is catching the error first. Hmm, I see if I can find a query that the domain model does not catch so that I can actually try the transaction support... Must obliged for great support! |
|
|
Yes, I know. But I reckoned a convertion to the correct date time format had to be made for the chosen culture. (e.g. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")) which would require a string data type in the domain model. But nope. The DateTime type in the domain model seems to work transparently. Case closed for me. |
|
|
One thing to note is that LS will always wrap a flush in a transaction if no user-level transaction is detected. Cheers, Andrew. |
|
|
Damn you are a quick responder. But höö? I reckon the user transaction use is if you would like to do several flushes (i.e. SaveChanges) within the transaction, correct? Might wanna update the manual with this info, no? |
|