Entity Framework - Persistence Model different from Domain Model

120 Views Asked by At

I have following lagacy code. There is a seperation between Pesistence Model and the (anemic) Domain Model. What is the benefit of this seperation and the implicit conversion ? Do you see any drawbacks ?

I know that with implicit conversion following is possible: SplitAmountEF saEF = dbContext.SplitAmount.Find(id); SplitAmount sa = saEF; //implicit conversion. They can be used interchangeable.

If the domain model is almost the same like persistence model, wouldnt it be better to use only the persistence model (without using Domain Model at all)?

Example:

//Domain Model
public class Booking 
{
  public Guid ID {get; set;}
  ....

}

public class SplitAmount
{
  public Guid ID {get; set;}
  public  Decimal Amount {get; set;}
  ...

  public Guid IDBooking {get; set;}
}


//Persistence Model   
public class BookingEF 
{
  public Guid ID {get; set;}
  ...       
}

public class SplitAmountEF
{
  public Guid ID {get; set;}
  public  Decimal Amount {get; set;}
  ...

  public virtual BookingEF Parent {get; set;}

  //implicit converstion from SplitAmountEF to SplitAmount
  public static implicit SplitAmount(SplitAmountEF saEF) 
  {
     return new SplitAmount() 
     {
       ID = saEF.ID,
       Amount = saEF.Amount,
       ...
       IDBooking = saEF.Parent.ID,
     }
  }

 //implicit converstion from SplitAmount to SplitAmountEF
 public static implicit SplitAmountEF(SplitAmount sa) 
  {
     return new SplitAmountEF() 
     {
       ID = sa.ID,
       Amount = sa.Amount,
       ...

     }
  }
}
0

There are 0 best solutions below