Welcome to the Milos Blog!

Monday, January 15, 2007
Atomic Saves and Transactions

One of our clients was having a problem with atomic saves and transactions in Milos, and it was kind of tricky to figure it out.

Business Objects were sharing the same data context so that the entities would get saved wrapped up on the same transaction. One of the Business Objects has a Business Rule that instantiates another Business Object and calls a method on it to check if a given row exists already on the database. In this scenario, the row was being added on the same transaction, but the call to this look up method was timing out (indicating that it couldn't read the row just added on the transaction. The code looked like this:

public
override void VerifyRow(DataRow currentRow, int rowIndex)
{
   if (!currentRow.IsNull("fkTrade"))
   {
    using (TradeBusinessObject oBizObj = new TradeBusinessObject())
      {
         Guid fkTrade = (Guid)currentRow["fkTrade"];

         string
tradeName = currentRow["TradeName"].ToString();
     DataSet ds = oBizObj.GetList(fkTrade);
         if (ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
         {
             this.LogBusinessRuleViolation(currentRow, rowIndex, "fkTrade", "The Trade '" + tradeName + "' does not exist.");
         }
      }
   }
}

Notice that the TradeBusinessObject has its own data context, and therefore, the call to GetList can't seem any row created by the transaction shared by main business object where the business rule lives in. All that needs to be done in this case is to make the object share the same data context, like so (the following line must come after the object is instantiated, but before the GetList method is called on it):

oBizObj.ShareDataContext((
BusinessObject)this.BusinessObject);



Posted @ 4:52 PM by Lassala, Claudio (lassala@foxbrasil.com.br)


Post a Comment:

Comment Title (required):

Your Name (optional):

Your Email (optional):

Your Web Site (optional):

Your Comment (required):


Archive:
November, 2010 (1)
July, 2009 (2)
February, 2009 (2)
January, 2009 (1)
December, 2008 (1)
October, 2008 (3)
June, 2008 (1)
April, 2008 (3)
February, 2008 (1)
January, 2008 (1)
December, 2007 (1)
October, 2007 (2)
September, 2007 (2)
July, 2007 (1)
June, 2007 (2)
May, 2007 (4)
April, 2007 (6)
March, 2007 (8)
February, 2007 (3)
January, 2007 (2)
December, 2006 (2)
November, 2006 (2)


Blog Stats:
Posts: 51
RSS Syndication

Contact:

EPS Software Corp.
6605 Cypresswood Dr., Suite 300
Spring, TX 77379
United States

Phone: 832-717-4445
Email: info@MilosSolutionPlatform.com

Other EPS Properties

EPS Software Homepage
EPS Custom Software
CoDe Magazine
CoDe Focus Magazine
VFPConversion.com
WPFExperts.com
MarkusEgger.com

(c) by EPS Software Corp. 2001 - 2013