访问包装对象

发布于 2024-10-18 23:33:24 字数 684 浏览 0 评论 0原文

我正在将 ORM 实体包装到业务对象中。

public class ProjectMember
{
    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; }
    } 
}

该业务对象由存储库返回。出路并不复杂。问题是当将包装对象传递到存储库以进行保存操作时如何访问包装实体。

获取包裹对象的巧妙方法是什么?

I'm wrapping my ORM entities into bussines objects.

public class ProjectMember
{
    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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心是晴朗的。 2024-10-25 23:33:24

只需添加一个方法或属性?

您可以像这样创建一个接口:

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

现在您可以让您的 BO 实现该接口。您甚至可以创建一个实现该接口的基类,并从该基类派生您的 BO。

编辑:
将 DTO 更改为实体以符合您的代码。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文