Do we loose all investment in Entity partial classes with move to Adapter mode?

Posts   
 
    
imakimak
User
Posts: 62
Joined: 18-Mar-2010
# Posted on: 14-Oct-2011 22:04:56   

LLBL Gen Pro v 2.6/SQL Server 2008/.net 3.5/Self Servicing

We have been using SelfServicing model for long time. During this process we have invested quite a bit in terms of creating our business logic in the partial classes for LLBL Entity classes. Not sure if it was the best approach but now there is a new requirement where our application could be used on the web with simultaneous users working on different database instances. Seem like natural approach is to start using Adapter model, however, seem like with that move we will not be able to use all the business logic we have imlemented in the partial classes for entities as Abapter model has no concept of Entities.

Please feel free to correct if my understanding is not correct and suggest what could be the best approach for moving forward.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 15-Oct-2011 03:32:32   

imakimak wrote:

Seem like natural approach is to start using Adapter model, however, seem like with that move we will not be able to use all the business logic we have imlemented in the partial classes for entities as Abapter model has no concept of Entities.

Adapter does know about entities. One of the main differences between Adapter and SelfServicing is that in SelfServicing mode you have the persistence logic inside entity classes. At the other hand, in Adapter the persistence logic is in an special object DataAccessAdapter, Entities are just containers objects without any persistence logic.

Suppose you SelfServicing partial class looks like:

public partial class OrderEntity
{
     public void RecalculateAndSave()
    {
          decimal total = 0;
          foreach (var detail in this.OrderDetails)
          {
                total += detail.Quantity * detail.Price; 
          }
          order.Total = total;
          this.Save();
    }
} 

... and the code that use it:

var order = new OrderEntity(5);
...
order.RecalculateAndSave();

Now in Adapter mode you will need to pass this into a business class and change it a bit:

public static class OrderManager
{
     public static OrderEntity GetOrder(int orderId)
     {
            var order = new OrderEntity(orderId);
            using (var adapter = new DataAccessAdapter())
           {
                  adapter.FetchEntity(order;
           }
           return order;
     }

     public static void RecalculateAndSave(OrderEntity order)
     {
          decimal total = 0;
          foreach (var detail in order.OrderDetails)
          {
                total += detail.Quantity * detail.Price; 
          }
          order.Total = total;
        
          using (var adapter = new DataAccessAdater())
         {
              adapter.SaveEntity(order);
         }
     }
}

... and the code that use it:

var order = OrderManager.GetOrder(5);
OrderManager.RecalculateAndSave(order);

So you will have to make some changes of course, but they should be straight-forward. To learn more about Adapter/SelfServicing differences read this.

David Elizondo | LLBLGen Support Team