4.1 Business objects creating other business objects async, is this kosher?

4.1 Business objects creating other business objects async, is this kosher?

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


JCardina posted on Wednesday, March 09, 2011

In a business library where Silverlight and .net need to be supported I have a class method in an object that returns a new object of the same type with all the fields copied over to create a duplicate object .

(I can't just call the standard New method because it won't work under silverlight so I'm caling the async method and waiting on the result which can't fail since the DataPortal_Create is simple property setting not involving the database)

Is this kosher?

public Client Duplicate()
        {
            Client dest = null;
            Client.New((o, e) =>
            {
                if (e.Error != null)
                    throw e.Error;
                else
                    dest = e.Object;
            });
            while (dest == null) ;//<--seems ugly but how else ?

... copy fields etc etc ...

}

RockfordLhotka replied on Wednesday, March 09, 2011

How about this (given that no database access is required)?

public Client Duplicate()
{
  var result = new Client();
  result.MarkNew();
  using (BypassPropertyChecks)
  {
    using (result.BypassPropertyChecks)
    {
      result.Name = this.Name;
      // copy all properties
    }
  }
  result.BusinessRules.CheckRules();
  return result;
}

JCardina replied on Wednesday, March 09, 2011

Yes, that would definitely work.  Thanks Rocky.

Copyright (c) Marimer LLC