FAQ Database Discussion Community


How to use the Repository Pattern to handle complex Reads(SELECTs)?

php,mysql,repository-pattern,laravel-5
I've seen a lot of the $repo->findAll() or $repo->findById($id)examples, but I'm looking for how to expand on this for more complex Reads. For example, let's say I have a datagrid that represents a SELECT query with several JOINs in it. I'm going to need to do these things: Sorting Filtering...

IEntity where Key/ID type unknown

c#,repository-pattern
I've been exploring the use of data repositories in C# as I'm working on my first "big" application in quite some time (and my first with C#). Particularly I used some information from http://web.archive.org/web/20150404154203/https://www.remondo.net/repository-pattern-example-csharp/ as well as the MSDN and stackoverflow. I seem to have gotten stuck at something that...

How to decouple eloquent from the service layer?

laravel,eloquent,repository-pattern,service-layer
I am attempting to create a clean cut service layer, whereby the service layer acts upon one or more repositories, and each repositories acts on its own eloquent model. For example, I may have: ForumService | +-- PostRepo extends PostInterface | | | +-- Post (Eloquent) | +-- UserRepo extends...

Use multiple conditions in join LINQ. i,e AND

c#,asp.net-mvc,linq,entity-framework-6,repository-pattern
How to use multiple condition in LINQ joins, i.e. in my scenario I need to get all the users from table User where group ID = 4 from table UserInGroup, where UserInGroup is intermediate table between User and Group table as in SQL-T we use join as select * from...

Pass list value to view model class variable in ASP.NET MVC

c#,asp.net-mvc,repository-pattern,asp.net-mvc-viewmodel
I need to pass list of records to class variable (Users and Groups) in view model but I cannot seeing view model object (_UserAndGroupModel) recognizing its class object, I am not sure exactly what I am missing here. ViewModel public class UserGroup_ViewModel { public User Users { get; set; }...

Queries on Repository Layer in MVC application

asp.net-mvc,repository-pattern,poco
I am building MVC 5 application using Razor. My application is layered as below: UI Layer: Comprising of Model, View and Controller. Data Access Layer: Connection and Stored Procedure classes Business Layer (Service Layer) Repository I referred to Contosso Sample Application. There it is using DAL to store Repository. But...

Automapper missing type map configuration or unsupported mapping

entity-framework,mongodb,automapper,repository-pattern,nuget-package
I have 2 class : Class 1 : (Domain) public class Book { public ObjectId Id { get; set; } public String ISBN { get; set; } public String Title { get; set; } public String Publisher { get; set; } public int? PageCount { get; set; } public Author...

Modern ORM vs Repository/IoW pattern

entity-framework,nhibernate,orm,repository-pattern,unit-of-work
I read a lots of content about the usage of Entity Framework/NHibernate (or basically any other modern ORM) with the repository/UnitOfWork patterns. Apparently the community is divided. Some would say the repository pattern is almost mandatory, some others would say that it's a waste of time... Well, I come up...

Why is my C# Inheritance not working with the Generic Repository Pattern

c#,asp.net-mvc,repository-pattern
I have defined a base repository as follows: public abstract class BaseRepository<TEntity> where TEntity : class { protected DbSet<TEntity> dbSet; protected readonly DbContext dbContext; public BaseRepository() { this.dbContext = new SchoolDemoEntities(); dbSet = dbContext.Set<TEntity>(); } public BaseRepository(DbContext dbContext) { this.dbContext = dbContext; dbSet = dbContext.Set<TEntity>(); } } The above is...

A specified Include path is not valid. The EntityType '*Propiedad' does not declare a navigation property with the name 'Nombre'

c#,asp.net-mvc,entity-framework,asp.net-mvc-4,repository-pattern
I am trying to implement unit of work and the generic repository pattern as explained here: http://www.asp.net/mvc/overview/older-versions/getting-started-with-ef-5-using-mvc-4/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application My entity Propiedad is like this: public class Propiedad { [Key] public int Id { get; set; } public virtual Entidad Entidad { get; set; } public string Codigo { get; set; }...

Accessing repository pattern through one more layer called service in Laravel

laravel,service,laravel-5,repository-pattern
I have created one repository layer in my project which is perfectly accessible through controller method using interface. Now What I want to add, is a service layer. that means I want all controller method operations will be done through the service. So I created one file inside the service...

Having a repository dependent on another repository

c#,repository-pattern,solid-principles
I've recently been spending time reading up on SOLID principles and decided to seeing how the code base I work with compares. In some of our code there is a repository (repository A). When a record is to be deleted from the repository A, we also need to delete an...

Fetching records taking some time using repository and dependency injection

asp.net-mvc,dependency-injection,repository-pattern,autofac,unit-of-work
I am creating 1 demo application to study repository and dependency injection. I am having just 10 to 15 records in my database tables and when reading it is taking some amount of times and i dont know why.is it because of repository or dependency injection?? so Please guide me...

DDD Repository: Use DAO for separation?

domain-driven-design,repository-pattern,dao
There is a controversial discussion of Repositories, their use and layout on stackoverflow and throughout the web. I am confused about how to implement the data access abstraction (e.g. database) behind a Repository efficiently. I am not using an ORM tool/framework as I want to see the gritty details myself....

Why do Examples of the Repository Pattern never deal with Database Connection Exceptions?

architecture,exception-handling,repository-pattern
I've read a lot of tutorials and seen a lot of code samples regarding implementations of the Repository pattern. In pretty much every case, exceptions that would result from attempting to hit the database when the database is unavailable is not addressed. This seems strange considering that this is a...

Repository/UnitOfWork Add throws Cannot insert the value NULL into column error

c#,.net,entity-framework,repository-pattern,n-tier-architecture
I am working on an application that GETs data from a REST API. I am parsing the json against a concrete class and then stepping through that piece to either Update or Insert (depending of if the row exists) into a SQL database. Part of this is creating a Unique...

Getting entity with referenced entities in EF

entity-framework,repository-pattern,unit-of-work
I have an entity called Study: public class Study { public Study() { Tasks = new List<Task>(); } [Key] public string StudyUid { get; set; } public virtual List<Task> Tasks { get; set; } } I use Unit of work design pattern, I would like to get the study with...

Performance Issues with Include in Entity Framework

json,entity-framework,repository-pattern,asp.net-web-api2,poco
I am working on a large application being developed using Repository Pattern, Web APIs, AngularJS. In one of the scenario, I am trying to retrieve data from a single lead which has relations with approx. 20 tables. Lazy loading is disable, so I am using Include to get the data...

When to expose an IEnumerable instead of an ICollection?

asp.net-mvc,entity-framework,ef-code-first,repository-pattern
public class Order { public int Id {get;set;} [DisplayName("User")] public long UserId { get; set; } [ForeignKey("UserId")] public virtual User User { get; set; } public decimal Amount { get; set; } } With IEnumurable public class User { public int Id{get;set;} public virtual IEnumerable<Order> Orders { get; set; }...

How to keep helper methods when using Repository pattern in Laravel 5?

laravel,repository-pattern,laravel-5,solid-principles
When working with repository pattern we have interface and some repository classes which implement this interface. If I'm not mistaken, one of the SOLID principles says that those repository classes should return the same type of data for each interface method so that if we switch implementation of the interface...

Why use database factory in asp.net mvc?

asp.net-mvc,repository-pattern
Recently I have worked with asp.net mvc and I saw in sample project is using Database Factory class. How can you explain for me why use it ? IDatabaseFactory class public interface IDatabaseFactory : IDisposable { EFMVCDataContex Get(); } DatabaseFactory class public class DatabaseFactory : Disposable, IDatabaseFactory { private EFMVCDataContex...

Unit Of Work in Generic Repository

c#,asp.net-mvc-4,repository-pattern,unit-of-work,onion-architecture
I want to move my Unit of work away from my business logic. In Infrastructure.Data I have NHibernateHelper public class NHibernateHelper { private ISessionFactory _sessionFactory; private readonly string _connectionString; public NHibernateHelper (string connectionString) { if (string.IsNullOrEmpty (connectionString)) throw new HibernateConfigException ("ConnectionString in Web.config is not set."); _connectionString = connectionString; }...

Updating records using a Repository Pattern with Entity Framework 6

c#,asp.net-mvc-5,entity-framework-6,asp.net-identity,repository-pattern
I'm writing a simple blog application and trying to establish CRUD operations in my generic repository pattern but I'm getting an error on my update method that says: 'System.Data.Entity.DbSet' does not contain a definition for 'Entry' and no extension method 'Entry' accepting a first argument of type 'System.Data.Entity.DbSet' could be...

Asp.Net MVC and Strategy pattern

asp.net-mvc,entity-framework-6,repository-pattern,strategy-pattern
I have an MVC application that uses Entity Framework. I am using a repository, unit of work and unity as dependency injection. The problem I have is that I have different authentication types, and each type I want a different class, so I decided to use the Strategy pattern public...

Generic Repository for SQLite-Net in Xamarin Project

xamarin,repository-pattern,sqlite-net
I am wondering if there is a way to write a generic repository for my Xamarin project versus writing a different Repository for each entity in my object. The Xamarin Tasky Pro example have one Repository for the Task entity because that is the only entity it has. In my...

architecture layering and unit of work pattern

architecture,repository-pattern,unit-of-work
I am trying to figure out a good practice to architecture / layering and unit of work. We use C#, write MVC front end apps. Normal structure at the moment is: MVC Service / Domain Layer Repository Layer EF6 MVC would simply call the service, (no logic here). The Service...

Why repository pattern is extensively used in entity framework as though it is complex?

c#,asp.net-mvc,entity-framework,repository-pattern,nopcommerce
I am creating a demo project which contains crud operations using a repository pattern and dependency injection. This is my structure: Approach 1 (very popular, used by many developers) My repository interface: public partial interface IRepository<T> { void Insert(T entity); } My service layer: public partial interface IEmployeeService { void...

Change DB in the runtime using Generic Repository and IoC

c#,repository-pattern,simple-injector
I'M developing N-Tir web application uses a database for each client with Simple Injector for IoC and generic repository pattern. When I tried to change the db connection I found that the injector runs in Application_Start in Glopal.asax where I still can't figure out who is the current user to...

Entites count in dependency injection and Repository Pattern

asp.net,asp.net-mvc,dependency-injection,repository-pattern
As a standard we make 'N' controllers for 'N' entities. Let say i have two entities one for student and one for course, i have to add student and add course, if i make interface for class that do crud operations for Student and another interface for class that does...

Do you place files processing logic in repositories? (Using generic repository and UoW pattern with EF)?

c#,.net,entity-framework,repository-pattern
I have a question. So I know that generic repository pattern and EF work very well when you need to work with Databse only. However in my case I need to load data from files and into the Database using Entity Framework and Generic Repository pattern. So here is my...

How to use Repository and Unit of Work Patterns with ADO.NET?

asp.net-mvc,design-patterns,ado.net,repository-pattern,unit-of-work
I am building ASP.NET MVC 5 application. I read about Repository and Unit of Work (UoW) Patterns here. These examples use Entity Framework which adds a high-level of abstraction itself. I am using ADO.NET and not EF. I want to know: Whether Repository and UoW patterns makes any sense with...

How can I wrap multiple business transactions under another transaction?

c#,transactions,repository-pattern,service-layer
In my project, a single service method is a business transaction. For instance, assume I have the following Service/Repository: public interface IDocumentService { void CreateDocument(Document doc); void AttachFileToDocument(int documentId, string filepath); } public class DocumentService { private readonly IDocumentRepository _repository; public DocumentService(IDocumentRepository repository) { _repository = repository; } public void...

Use viewmodel to bind data with html.dropdownlistFor in asp.net-MVC

c#,asp.net-mvc,repository-pattern,html.dropdownlistfor,model-view
I need to create @html.dropdownlistFor where data is coming from database. I have modelView which combining two classes. One for user and another one is Group. it suppose to show records of user in grid table along with drop down where group can be selected for that particular user. View...

Refactoring code using Entity Framework 6 to follow TDD [closed]

c#,asp.net,asp.net-mvc,entity-framework,repository-pattern
Right now, I'm on a task to refactor an ASP.Net MVC application that using EF6. Currently, the code use EF Designer to generate the entities (edmx file) and all of the logic bloated the controller. I've read some article about TDD and EF6, and I know this question is similar...

Generic Repository Pattern IEntity property case sensitivity

c#,asp.net-mvc,design-patterns,repository-pattern
I am using Generic Repository Pattern in my application. I am trying this post http://www.remondo.net/repository-pattern-example-csharp/. The question is, database code generation tool (code first from existing database) generated following models: [Table("TableName1")] public partial class TableName1 : IEntity { public int ID { get; set; } [StringLength(50)] public string Name {...

What is a better more testable way for Repository based on tenants

c#,unit-testing,design-patterns,repository-pattern
I have a repository that receives a data layer as parameter and a tenantID like this. (Code is simplefied) public class MyRepsitory{ private readonly IDataAccess _dataAccess; private readonly string _tenantID; public MyRepsitory(IDataAccess dataAccess, string tenantID) { _dataAccess = dataAccess; _tenantID = tenantID; } } } This repository has also a...

How to deploy solution from Visual Studio with multiple projects to Azure

azure,visual-studio-2013,asp.net-mvc-5,repository-pattern,web-deployment
I am developing an MVC web app using the repository pattern, so there are many projects in one Visual Studio solution dependent on each other. I use Visual Studio 2013 The view layer is my startup project, I have Business logic;Data Access;Model;and service layers. The project works on my local...

Repository pattern: DAL or BLL [closed]

c#,repository-pattern,business-logic,bll
I'm trying to implement a business logic layer with a few use case for saving data of Booking of a Vehicle. I'm a bit confused as to where the Repository pattern should be implemented. Should I use it in BLL or DAL? It sounds very basic but I'm kind of...

ASP.NET MVC Details view with many display fields but a single editable field

asp.net-mvc,entity-framework-6,repository-pattern,asp.net-mvc-viewmodel
I have a view that shows a single item with all of its fields. But I'm getting confused trying to figure out how to allow one specific field ("Status") to be updated from this view, without necessarily going into a whole other "edit" view first. How do I http-post to...

Visibility of inherited class methods does not make sense?

c#,entity-framework,inheritance,repository-pattern,unit-of-work
The following code represents my effort at a Unit of work. Interfaces: public interface IUnitOfWork { IFieldRepository FieldRepository { get; } void Save(); } public interface IFieldRepository { IEnumerable<Field> GetAllFields( int page, int amount, string sortByKey, SortDirection sortDirection ); } Concrete unit of work class: public class EFUnitOfWork : IDisposable,...

Sharing promises between modules vs having multiple promises

javascript,node.js,promise,repository-pattern,q
I am implementing Node.js logic with controllers and repository using Kris Kowal's Q library. I have a feeling that the way I use promises in the example below is not correct. But I can't find any guidance on proper pattern how to use promises through multiple layers or functions. Am...