没有 ORM 的存储库用于保存对象图
我知道创建存储库来检索域模型而无需 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我很难找到解决方案。
没有 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/