title: c# mapping between Domain Entity and Data Entity in Repository Pattern and unit of work project
body: <p>I have SOA Layer architecture for C# application. I have defined Business/ Domain Entities in Business Access Layer 'Class Library Project'.... Data Entities in Data Access Layer 'Class Library Project' and Data Contract for Server side WCF is under WCF Service 'Class Library Project'</p>
  
  <h2>Business Entity</h2>
  
  <pre><code>namespace App.Core.Entities
  {
  public class Member
  {
      public int MemberID { get; set; }
  
      public string Title { get; set; }
  
      public string Surname { get; set; }
  
      public string Forename { get; set; }
  
      public string MiddleName { get; set; }
  }
  </code></pre>
  
  <h2>Data Entity</h2>
  
  <pre><code>namespace App.DAL.Entities
  {
  [Table("Member")]
  public class Member
  {
      [Key]
      public int MemberID { get; set; }
  
      public string Title { get; set; }
  
      public string Surname { get; set; }
  
      public string Forename { get; set; }
  
      public string MiddleName { get; set; }
  
    }
  </code></pre>
  
  <p>}    </p>
  
  <h2>WCF Data Contract</h2>
  
  <pre><code>namespace App.Services.Contracts 
  {
  [DataContract]
  public class MemberData : IIdentifiableEntity
  {
      [DataMember]
      public int MemberID { get; set; }
  
      [DataMember]
      public string Title { get; set; }
  
      [DataMember]
      public string Surname { get; set; }
  
      [DataMember]
      public string Forename { get; set; }
  
      [DataMember]
      public string MiddleName { get; set; }
  
      int IIdentifiableEntity.EntityId
      {
        get { return MemberID; }
        set { MemberID = value; }
      }
    }
  }
  </code></pre>
  
  <h2>generic repository</h2>
  
  <pre><code> public interface IGenericRepository&lt;TEntity&gt; where TEntity :class
  {
  
      global::System.Linq.IQueryable&lt;TEntity&gt; GetAll();
      TEntity GetEntityByID(int id);
      void InsertEntity(TEntity obj);
      void UpdateEntity(TEntity obj);
      void DeleteEntity(int id);
  
  }
  </code></pre>
  
  <h2>Unit of work</h2>
  
  <pre><code>namespace App.Repository.UnitOfWork
  {
   public class MembershipManagement_UOF:IDisposable
   {        
      protected Member_Repository _Member_Repository;  
  
     public Member_Repository Member_Repository
      {
          get
          {
              if (this._Member_Repository == null)
              {
                  this._Member_Repository = new Member_Repository(_MembershipContext);
              }
  
              return _Member_Repository;
          }
      }    
    }
  </code></pre>
  
  <p>Now my issue is when I run code from business project, it should only talk to repository and use only Business entity for Member but it asking me to add reference from DAL in business project</p>
  
  <p>here is code where I get Error</p>
  
  <pre><code> public IEnumerable&lt;Member&gt; GetAllMember()
      {
          using (var _uof = new MembershipManagement_UOF())
          {
              var entities = _uof.Member_Repository.GetAll();
  
              // return entities.ToList();
  
              return null;
          }
      }
  </code></pre>
  
  <h2>error</h2>
  
  <pre><code>Severity    Code    Description Project File    Line    Suppression State
   Error  CS0012  The type 'Member' is defined in an assembly that is not referenced. You must add a reference to assembly 'App.DAL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.  App.CoreServices    C:\My Work\Credit Union  Application\CreditSolutionApp\App.CoreServices\CoreServices\MembershipCore\MembershipCore.cs   23  Active
  </code></pre>