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.