c# – 是否存在在基于DDD的分层体系结构中使用模型和数据访问层
我一直在阅读Tim McCarthy的
awesome book on DDD in .NET.虽然在他的示例应用程序中,他的基础数据访问是使用SqlCE并且他手工编写SQL内联.
我一直在使用一些模式来利用Entity Framework,但我已经陷入了如何将IRepository linq查询映射到底层数据访问层的问题. 我有一个名为的具体存储库实现. public EFCustomerRepository : IRepository<DomainEntities.Customer> { IEnumerable<DomainEntities.Customer> GetAll( Expression<Func<DomainEntities.Customer,bool>> predicate) { //Code to access the EF Datacontext goes here... } } 在我的EF模型中,我正在使用POCO实体,但即使如此,我的DomainEntity.Customer&之间也没有原生映射.我的DataAccessLayer.Customer对象. 所以我不能只传递Expression< Func< DomainEntities.Customer,bool>>谓词作为EFContext.Customers.Where(…)的参数; 是否有一种简单的方法来映射 或者我这样做错了吗? 解决方法
从您的示例中提供的代码我猜您没有使用通用存储库模式?
我使用EF CodeFirst(但它适用于旧EF),具有通用存储库模式… http://average-uffe.blogspot.com/2011/03/repository-pattern-with-ef-code-first.html 我没有Expression< Func< DomainEntities.Customer,bool>> 界面: IEnumerable<T> Find(Expression<Func<T,bool>> expression,int maxHits = 100); 并在抽象baserepository中实现: public virtual IEnumerable<T> Find(Expression<Func<T,int maxHits = 100) { return this.DataContext.DbSet<T>().Where(expression).Take(maxHits); } 现在你可以通过lambda表达式在任何实体上调用Find … 如果你没有把它弄好,我可以发布一个完整的例子,只是说什么时候. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |