Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you ned such kind of decoupling and separation of entities - you can create <a href="http://en.wikipedia.org/wiki/Data_transfer_object" rel="nofollow">DTO</a> object along with each business object and use DTO to communicate with Service. But if you have a lot of business entities consider an other approach to avoid maintenance hell.</p> <pre><code>public sealed class ExportProductDto { public(ProductForExport exportProduct) { // initialize fields this.ExportId = exportProduct.ExportId; } public int ExportId { get; private set; } } </code></pre> <p>BTW, An overkill solution with operator overload, use <a href="http://en.wikipedia.org/wiki/Adapter_pattern" rel="nofollow">Adapter pattern</a> to convert between product types</p> <p>To decouple adapting from entities itself implement following interface your self:</p> <pre><code>public interface IProductAdapter&lt;TImport, TExport&gt; { TImport ToImportProduct(TExport exportProduct); TExport ToExportProduct(TImport importProduct); } </code></pre> <p>Or an other adapter approach:</p> <pre><code>// Implement this interface for ProductForImport class // public class ProductForImport : IExportProductAdapter, Product public interface IExportProductAdapter { ProductForExport ToExportProduct(); } // Implement this interface for ProductForExport class // public class ProductForExport : IImportProductAdapter, Product public interface IImportProductAdapter { ProductForImport ToImportProduct(); } </code></pre> <p><strong>EDIT: Answer to comments</strong></p> <pre><code>// An example of IExportProductAdapter adapter implementation public sealed class ProductForImport : Product, IExportProductAdapter { public int ImportId { get; set; } public ProductForExport ToExportProduct() { ProductForExport p = new ProductForExport(); p.Id = this.Id; p.IsExportable = true; p.ExportId = 0; return p; } } </code></pre> <p>And then instead of:</p> <pre><code> ProductForExport pfe2 = (ProductForExport)pfi; </code></pre> <p>You can do:</p> <pre><code> ProductForExport pfe2 = pfi.ToExportProduct(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload