Once you understood the basic ways of utilizing the CsharpGears Framework Database Access, now I will show you how to treat the SQL queries as transactions. Please note that in order to use the SQL transactions entities, you first need to add a reference to the System.Transactions namespace. After that, using the transaction database entity is very easy and similar to the previous examples:
TransactionDbEntity<LogMessage> tDbEntity = new TransactionDbEntity<LogMessage> ("LogRead",ConnectionString); List<LogMessage> list = (List<LogMessage>)(tDbEntity.Select());
Here I consider retrieving the log from a database as list of LogMessage instances. The LogMessage class basically contains ID, Sender, Description and Date properties that need to be bound.This Database entity essentially creates CommitableTransaction object inside and commits it if the query passes successfully, otherwise performs rollback. But once again, my point was to show you how easy is to treat queries as transactions. Nevertheless, you can still write the transaction handling in the storet procedure's body, but just in case you have already written hundreds of procedures without database transactions, this class might come in handy.
No comments:
Post a Comment