开发者

Access wrapped object

I'm wrapping my ORM entities into bussines objects.

public class ProjectMember
开发者_StackOverflow中文版{
    private readonly TfProjectMembersEntity _projectMembersEntity;

    public ProjectMember(TfProjectMembersEntity projectMembersEntity)
    {
        _projectMembersEntity = projectMembersEntity;
    }

    #region Props

    public string Email
    {
        get { return _projectMembersEntity.Email; }
        set { _projectMembersEntity.Email = value; }
    }

    public DateTime Created
    {
        get { return _projectMembersEntity.Created; }
        set { _projectMembersEntity.Created = value; }
    } 
}

This bussines objects are returned by the repository. The way out isn't complicated. The problem is how to access the wrapped entity when a wrapped object is passed to a repository for a save operation.

What would be a neat way, to get the wrapped object ?


Simply add a method or property?

You could create an Interface like so:

interface IWrappedEntity<T>
{
    T GetWrappedEntity();
}

Now you could make your BOs implement that interface. You could even create a base class implementing that interface and derive your BOs from that base class.

EDIT:
Changed DTO to Entity to conform with your code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜