[英]c# mapping between Domain Entity and Data Entity in Repository Pattern and unit of work project
I have SOA Layer architecture for C# application. 我有用于C#应用程序的SOA层体系结构。 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'
我在业务访问层“类库项目”中定义了业务/域实体。...在数据访问层“类库项目”中的数据实体和服务器端WCF的数据合同在WCF服务“类库项目”下
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; }
}
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; }
}
} }
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; }
}
}
}
public interface IGenericRepository<TEntity> where TEntity :class
{
global::System.Linq.IQueryable<TEntity> GetAll();
TEntity GetEntityByID(int id);
void InsertEntity(TEntity obj);
void UpdateEntity(TEntity obj);
void DeleteEntity(int id);
}
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;
}
}
}
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 现在我的问题是,当我从商业项目中运行代码,它应该只跟存储库并使用唯一的业务实体的成员,但它让我把DAL商业项目中添加引用
here is code where I get Error 这是我得到错误的代码
public IEnumerable<Member> GetAllMember()
{
using (var _uof = new MembershipManagement_UOF())
{
var entities = _uof.Member_Repository.GetAll();
// return entities.ToList();
return null;
}
}
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
It's a bit difficult to tell from the original post, but I suspect that your concrete implementation of the IGenericRepository
interface is referencing the Member
class from the DAL rather than from the BLL (Business Logic Layer). 从原始帖子中很难分辨出来,但是我怀疑您对
IGenericRepository
接口的具体实现是从DAL而不是从BLL(业务逻辑层)引用Member
类。 The concrete repository needs to use the Member
class from the BLL as its generic TEntity
type. 具体的存储库需要使用BLL中的
Member
类作为其通用TEntity
类型。 The methods of the concrete repository class need to load the data from the DB using the DAL Member
class, and then map those DAL Member
instances to BLL Member
instances, and then return the BLL Member
instances. 具体存储库类的方法需要使用DAL
Member
类从数据库加载数据,然后将那些DAL Member
实例映射到BLL Member
实例,然后返回BLL Member
实例。
Renaming the DAL Member class to something like MemberDto might help avoid confusion here. 将DAL成员类重命名为MemberDto之类的内容可能有助于避免混淆。 So, you might end up with something like (where
IGenericRepository<TEntity>
is in your BLL and MyMemberRepo
is in your DAL): 因此,您可能最终会
IGenericRepository<TEntity>
类似的情况(其中IGenericRepository<TEntity>
在BLL中,而MyMemberRepo
在DAL中):
public class MyMemberRepo : IGenericRepository<Member>
{
public IEnumerable<Member> GetAllMember()
{
// 1. Load the data from the data store into an IEnumerable<MemberDto>.
// 2. Map the IEnumerable<MemberDto> to an IEnumerable<Member>, perhaps
// using something like the open source AutoMapper project.
// 3. Return the IEnumerable<Member>.
}
// ... other interface implementations...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.