没有 ORM 的存储库用于保存对象图

发布于 2024-07-26 17:01:10 字数 971 浏览 1 评论 0原文

我知道创建存储库来检索域模型而无需 ORM 是相当简单的(存储库模式没有 LINQ 或其他 ORM?)。 但是,如何保存域模型及其内部对象图呢?

public class Car: IAggregateRoot, IEntity, ICar
{
  public IEnumerable<IWheel> Wheels {get; set;}
}

public class CarRepository
{
  public void Save(ICar car) 
  {
    // calls Dao
    // update/insert all wheels as required
    // update/insert car as required
  }
}

这里我们需要考虑变更跟踪等。如何实施呢?

对于我的具体实现,我将 Linq to Sql 视为 Dao。 Linq to sql 确实更改了跟踪,但我创建的域模型却没有。 它们是直接 POCO,不是通过 linq 直接映射到 sql。 一切都是由自定义 DataMapper 完成的

public class CarDataMapper : IMapper<LinqData.Car, Domain.ICar>
{
  public ICar Map(LinqData.Car linqCar)
  {
    ICar = new Car () { Wheels = linqCar.Wheels.Select( w => new WheelDataMapper().Map(w));
  }
}

有没有直接的方法来实现存储库来保存对象图而不将 linqToSql 或 NHibernate 暴露给域层? 或者我在这里遗漏了什么?

I know it's fairly straight forward to create Repository for retreiving domain models without ORM (Repository Pattern without LINQ or other ORM?). However, what about saving domain models and its internal object graph?

public class Car: IAggregateRoot, IEntity, ICar
{
  public IEnumerable<IWheel> Wheels {get; set;}
}

public class CarRepository
{
  public void Save(ICar car) 
  {
    // calls Dao
    // update/insert all wheels as required
    // update/insert car as required
  }
}

Here we need to take about change tracking etc. How does one go about to implement it?

For my specific implementation I'm treating Linq to Sql as Dao. Linq to sql does change tracking but the domain models that I created are not. They are straight POCO and not mapped directly by linq to sql. Everything is done by a custom DataMapper

public class CarDataMapper : IMapper<LinqData.Car, Domain.ICar>
{
  public ICar Map(LinqData.Car linqCar)
  {
    ICar = new Car () { Wheels = linqCar.Wheels.Select( w => new WheelDataMapper().Map(w));
  }
}

Is there any straight forward way to implement Repository to save object graph without exposing linqToSql or NHibernate to the domain layer? Or am I missing something here?

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

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

发布评论

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

评论(1

生生漫 2024-08-02 17:01:10

我很难找到解决方案。

没有 ORM 的 DDD,有可能吗?
看看 http:// /solveme.wordpress.com/2009/11/11/ddd-without-any-orm-tool-is-it-possible/

I am too struggling to find out solution..

DDD without ORM, is it possible..
Look at http://solveme.wordpress.com/2009/11/11/ddd-without-any-orm-tool-is-it-possible/

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