repository-pattern

Replacing a full ORM (JPA/Hibernate) by a lighter solution : Recommended patterns for load/save?

耗尽温柔 提交于 2019-12-04 07:39:55
问题 I'm developing a new Java web application and I'm exploring new ways (new for me!) to persist the data. I mostly have experience with JPA & Hibernate but, except for simple cases, I think this kind of full ORM can become quite complex. Plus, I don't like working with them that much. I'm looking for a new solution, probably closer to SQL. The solutions I'm currently investigating : MyBatis JOOQ Plain SQL/JDBC, potentially with DbUtils or some other basic utility libraries. But there are two

How is the Data Mapper pattern different from the Repository Pattern?

回眸只為那壹抹淺笑 提交于 2019-12-04 07:39:47
问题 I found two patterns which appear to have the same goal - what is the difference? http://martinfowler.com/eaaCatalog/dataMapper.html http://martinfowler.com/eaaCatalog/repository.html 回答1: [the Repository is] another layer of abstraction over the mapping layer where query construction code is concentrated. The DataMapper ensures the DB side of the fence doesn't need to know about the specifics of your business logic and how the data is kept in memory by your business objects and your business

how to design Repository pattern to be easy switch to another ORM later?

核能气质少年 提交于 2019-12-04 07:30:55
I am new to repository pattern but i tried, my goal is to make a design which will let me easily with just some few edits "dependency injection, or configuration edits" to be able to switch to another ORM without touching other solution layers. I reached this implementation: and here is the code: public interface IRepository<T> { T Get(int key); IQueryable<T> GetAll(); void Save(T entity); T Update(T entity); // Common data will be added here } public interface ICustomerRepository : IRepository<Customer> { // Specific operations for the customers repository } public class CustomerRepository :

Repository pattern vs. “smart” business objects [closed]

痴心易碎 提交于 2019-12-04 07:27:25
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . I see two main "schools of thoughts" when it comes to creating larger-scale enterprise-wide apps on .NET (Winforms, WPF, ASP.NET). Some folks use the "repository pattern" which uses a repository that knows how to fetch, insert, update and delete objects. Those objects are

DDD - Persistence Model and Domain Model

爱⌒轻易说出口 提交于 2019-12-04 07:24:37
问题 I am trying to learn domain-driven design (DDD), and I think I got the basic idea. But there is something confusing me. In DDD, are the persistence model and domain model different things? I mean, we design our domain and classes with only domain concerns in mind; that's okay. But after that when we are building our repositories or any other data persistence system, should we create another representation of our model to use in persistence layer? I was thinking our domain model is used in

How to reuse projections in Entity Framework?

廉价感情. 提交于 2019-12-04 07:14:20
I have an ASP.NET MVC application which uses Entity Framework to get data. I need to transform Entites to Models before passing them to View. Projections can be very complex, but to keep it simple: public static IQueryable<UserModel> ToModel(this IQueryable<User> users) { return from user in users select new UserModel { Name = user.Name, Email = user.Email, }; } This can be used in a controller like this: return View(Repository.Users.ToModel().ToList()); Very good. But what if I want to use this projection inside another one? Example: public static IQueryable<BlogPostModel> ToModel(this

Foreign key constraint, EF with collection of childobjects

帅比萌擦擦* 提交于 2019-12-04 06:10:30
问题 I'm trying to update a model, but get the error "The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable. When a change is made to a relationship, the related foreign-key property is set to a null value. If the foreign-key does not support null values, a new relationship must be defined, the foreign-key property must be assigned another non-null value, or the unrelated object must be deleted." From what I understand from

ORM / How to deal with the correspondence between Domain object and Persistent object?

允我心安 提交于 2019-12-04 04:34:10
问题 In an application, there are at least two ways for dealing with domain object persistence and an ORM. Mapping directly the domain object to persistence using some kind of ORM (xml or annotations) Making separation of concerns in case of a lot of impedance mismatch between your domain and your persistent model (table columns). That means, domain object is persistence agnostic and there are some conversions to some corresponding persistent object, this latter maps to an ORM. As pure DDD

Repository + UnitOfWork pattern for entity framework

﹥>﹥吖頭↗ 提交于 2019-12-04 03:19:57
I was searching the net up and down and I didn't manage to find a suitable design for my application. I am looking for Repository+UnitOfWork pattern that will manage connections and dispose them automatically when done. I need to support both web application where each request will have its own UnitOfWork and windows application where each thread will have its own UnitOfWork. I need the patters to dispose automatically the UnitOfWork whrn request/thread is done. I also would like to support rolback in case of exception. Right now I use StructureMap so I don't care to continue use it in the

Transactions in the Repository Pattern using ServiceStack.ORMLite

不打扰是莪最后的温柔 提交于 2019-12-04 02:50:00
I'm implementing Repository Pattern using ServiceStack.ORMLite like this: public class MyRepository : IMyRepository { private IDbConnectionFactory DbConnectionFactory = null; public MyRepository(IDbConnectionFactory dbConnectionFactory) { DbConnectionFactory = dbConnectionFactory; } public void MyMethod() { using (var connection = DbConnectionFactory.OpenDbConnection()) using (var cmd = connection.CreateCommand()) { //Do something here } } } But I don't know how to handle DbTransaction when I need to warp some DB operation in a DbTransaction.It looks like TransactionScope is a solution but I