repository-pattern

RxJava: concatArrayEager not emitting result from repository for offline case when concatArray is

£可爱£侵袭症+ 提交于 2019-12-11 15:07:20
问题 I have an app with offline functionality that requests data from a repository for getting data from a local database and an api request. The api call updates the local database so that in case the app is offline data is stored in the db is still displayed. My ProjectRepository class has a function getAllProjectByUserId which returns an Observable which combines output from two sources (the database and api call) fun getAllProjectByUserId(userId: Int): Observable<Projects> { // concatArray

Best way to handle complex entities (relational) with Generic CRUD functions

前提是你 提交于 2019-12-11 14:39:44
问题 I have tried using this generic functions to insert-update Entities but I always thought that maybe I am doing this totally wrong so therefore I would like to have your opinions/suggestions. These are my Insert & Update functions: public static bool Insert<T>(T item) where T : class { using (ApplicationDbContext ctx = new ApplicationDbContext()) { try { ctx.Set<T>().Add(item); ctx.SaveChanges(); return true; } catch (Exception ex) { // ... } } } public static bool Update<T>(T item) where T :

Difference between updating an entity by using a foreign key and using the navigation properties In Entity Framework

浪尽此生 提交于 2019-12-11 12:53:29
问题 -I Want to know the Difference between updating an entity by using foreign key and using the navigation properties in Entity Framework. -Is there a way to update a complex object with only one call to the database? 回答1: Using the Foreign key to update an entity is preferable over the navigation property, simple because you won't have to deal with the state of the entities. The most common problem with updating entities using navigation properties is getting duplicates records when you

Ninject UOW pattern, new ConnectionString after user is authenticated

人走茶凉 提交于 2019-12-11 12:15:42
问题 I wonder if any one can point me in the right direction? I am using the UOW repository pattern and have my dependencies injected via Ninject. I have a UnitOfWorkMapping class which inherits from NinjectModule, which I use to bind my IUnitOfWork to a concrete implementation of Dbcontext, see below public class UnitOfWorkMapping : NinjectModule { public override void Load() { Bind<IUnitOfWork>() .To<WebsiteDbContext>() .InRequestScope() .WithConstructorArgument( "connectionString",

How to handle different responsibilities while using only one instance of DbContext

我只是一个虾纸丫 提交于 2019-12-11 11:16:17
问题 I have been looking around for an answer to my question but couldn't find one, mostly because I don't really know how to phrase it! I am playing around with EF code first and trying to implement some sort of repository pattern whilst using dependency injection (thanks to Unity). I am also trying to keep to SOLID (well, the SRP part at least) in that I have IStaffRepository and IDepartmentRepository interfaces which in turn implement IRepository<TEntity> which provides basic CRUD methods. My

Transaction scope in EF Repository?

僤鯓⒐⒋嵵緔 提交于 2019-12-11 10:49:25
问题 I am using the repository pattern with EF. In my project we are using two databases and these two databases are sitting in two different projects. For any time one project is a CoreLib (we are referring in the other). I have the following questions. Can I use one repository layer for the two projects? How can I provide the transaction safety using System.Transactions.TransactionScope? Note: I am using Microsoft's unity framework and UnitOfWork pattern. Thanks for your reply. I have

Decorator Chaining of Repositories and Specialized Repositories with Dependancy Injection

笑着哭i 提交于 2019-12-11 09:48:38
问题 Right now I'm trying to figure out a way to do things smarter, and in the course of doing so all i've managed to do is use a full bottle of excedrin in a single day. Assume i have an interface called IRepository like so. public interface IRepository<T> { T Get(int id); void Add(T value); void Update(T value); void Delete(T value); ... } And assume i have an implementation like public class NHibernateRepository<T> { ... } Now, all is fine and good, i can do all my basic operations against the

C#: How to create a generic superclass to be extended by non-generic subclasses

送分小仙女□ 提交于 2019-12-11 09:14:36
问题 I have a bunch of Repository classes which all look a bit like the following. Note that I have omitted certain methods; I just want you to get a flavour. public class SuggestionRepository : ISuggestionRepository { private IUnitOfWork _unitOfWork; public SuggestionRepository(IUnitOfWork unitOfWork) { _unitOfWork = unitOfWork; } public Suggestion Load(int id) { Suggestion suggestion; suggestion = _unitOfWork.Load<Suggestion>(id); return suggestion; } public IQueryable<Suggestion> All { get {

Repository Pattern with Entity Framework and MVC4 Building Dynamic Connection String

筅森魡賤 提交于 2019-12-11 08:23:20
问题 I am facing an issue while implementing the Repository Pattern [UoW] for MVC4 with EF6. Error: 'XX.DataAccess.Context' must be a non-abstract type with a public parameterless constructor in order to use it as parameter 'TContext' in the generic type or method 'XX.DataAccess.WriteRepository' //Data Access layer Class for Saving/Deleting/Retriving etc. Inherits WriteRepository public class Common : WriteRepository<Context>, ICommon { //Method } //Repository Pattern public abstract class

Multiple dbcontexts with Repository, UnitOfWork and Ninject

那年仲夏 提交于 2019-12-11 07:45:16
问题 I am slowly getting to grips with EF, repository, UnitOfWork and Ninject and have included my implementation so far (see below). The purpose of my data layer is to provide the ability to read data from the existing HR system which has an Oracle back end, and provide addition functionality by consuming this data. The application I am building will use a SQL backend, currently I have just created some extra tables in the HR systems Oracle dbm but I want to keep this separate and hook in to