repository-pattern

UnitOfWork and Entity Framework Contexts

不想你离开。 提交于 2019-12-07 13:47:26
So the problem I am trying to solve is this; We are using Entity Framework to access our Oracle database that has 1200-1500 tables. Now mind you we are not accessing them all, but possibly could have 800+ to access. We are using the UnitOfWork --> Repository --> Service pattern and that works great, but we are trying to figure out if we should have one big DbContext, or multiple little contexts that are specific to the task at hand. Our UnitOfWork is setup using an EFUnitOfWorkBase like so: public abstract class EFUnitOfWorkBase : IUnitOfWork { private bool isDisposed = false; public

How can I wrap Play/JPA's Model class with a generic Repository?

久未见 提交于 2019-12-07 11:31:43
问题 I don't like working with models objects directly, because this breaks encapsulation. Instead, I prefer the Repository Pattern. When I try to implement a simple repository public abstract class BaseRepository<T extends Model> { public T findOne(String query, Object... params) { GenericModel.JPAQuery result = T.find(query, params); return result.first(); } } public class UserRepository extends BaseRepository<User>{} UserRepository repo = new UserRepository(); repo.findOne("byUsername", "test")

IUnitOfWork how to use - best practice

≯℡__Kan透↙ 提交于 2019-12-07 10:31:55
问题 I'm using EF4.3.1 in a .Net4.0 web forms (not MVC!) application. I tend to use the repository pattern with an IUnitOfWork interface. But I'm wondering if I'm following best practices, especially since most examples I've followed are based on MVC apps. I will say it's only a small web app, so that may affect the solution choices. The solution currently has 3 projects, Model, Logic and Site. Model contains the codefirst entities and the IUnitOfWork interface. Logic contains the repositories and

Is it ok for a DDD repository work with summary objects in addtion to “real” objects

北城余情 提交于 2019-12-07 09:39:50
问题 Say I'm creating a repository to store digital E-Books as shown in the interface below. This repository will store the actual text of the book, as well as the metadata that identifies the book (title, author, publisher, ISBN etc..). public interface IBookRepository { void AddBook(Book newBook); void DeleteBook(int bookId); void UpdateBook(Book updatedBook); Book GetBook(int bookID) } public class Book { public int BookId {get; set;} public string Title {get; set;} public string Author {get;

Managing Transactions either in service layer or repository layer?

老子叫甜甜 提交于 2019-12-07 07:38:43
问题 I have a certain scenario where inserts and updates are done on multiple tables based on some constraints ..so its natural to use Transaction scope for these scenarios.Now,I have a respository layer and a service layer. service layer mediates the repository and the UI and is persistent ignorant. Now i m confused where to use the transactions either in service or in repository layers.I am not using any ORMs. I have also seen people advocating about Unit of work pattern for such scenarios. are

MVC: Repositories and Services

杀马特。学长 韩版系。学妹 提交于 2019-12-07 06:51:51
问题 I am confused as to the limitations of what gets defined in the Repositories and what to leave to the Services. Should the repository only create simple entities matching tables from the database or can it create complex custom object with combinations of those entities? in other words: Should Services be making various Linq to SQL queries on the Repository? Or should all the queries be predefined in the Repository and the business logic simply decide which method to call? 回答1: You've

Few things about Repository Pattern that I simply don't understand

送分小仙女□ 提交于 2019-12-07 02:47:51
问题 I've read quite a few topic on what Repository is, but there are still few things bugging me. To my understanding only difference between Repository and traditional data access layers are Repository's query construction capabilities ( ie Query Object pattern ). But when reading the following definitions of a Repository Pattern , it seems we can still have Repository even if we don't implement Query Object pattern : a) From: Repositories are the single point where we hand off and fetch objects

Reusable Querying in Entity Framework WITHOUT Repository. How?

試著忘記壹切 提交于 2019-12-07 01:32:35
问题 Let me say, I have come to the conclusion (after a lot of trial) that Repository & Unit of Work when using Entity Framework is just wrong, wrong, wrong and this says why quite well. But I really hate on those embedded queries. Question is, where can I put them instead if I'm so against a repository, etc? (clean answers only please, examples much appreciated). I just nuked two projects containing my repositories, unit of work and interfaces with hundreds of files because the payback was

How to use joins with generic repository pattern - Entity Framework

女生的网名这么多〃 提交于 2019-12-06 19:10:29
I have a Generic Repository like below which handles my CRUD , for a single entity its easy to use, problem starts when i try to join my POCOs . Lets say I have these POCO, they are mapped using fluent api (many to many and One to many relation) : public class Student { public Student() { this.Courses = new HashSet<Course>(); } public int StudentId { get; set; } public string StudentName { get; set; } //FKs public virtual Standard Standard { get; set; } public int StdandardRefId { get; set; } public virtual ICollection<Course> Courses { get; set; } } public class Course { public Course() {

How to make a repository for class with <T> in EF

时间秒杀一切 提交于 2019-12-06 16:12:25
问题 I have a simple class: public class TestClass<T> { public int ID { get; set; } public T Value { get; set; } } Is is possible to use EF Code First and Repository pattern to save this kind of elements to SQL database? Edit : It seems like the DbSet's cannot be created using the -notation. E.g. public class UnitOFWorkTestContext : DbContext { ... public DbSet<TestClass<int>> TestClass_Int { get; set; } ... } Gives error: The type 'UnitOFWorkTest.Models.TestClass`1[System.Int32]' was not mapped.