repository-pattern

Asp.Net MVC and Strategy pattern

时光毁灭记忆、已成空白 提交于 2019-12-13 22:04:16
问题 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 interface IAuthStrategy { OperationResponse<AuthenticationMechanismDTO> GetAuthenticationMechanism(string userName); } public class AuthStrategy { readonly IAuthStrategy _authStrategy; public AuthStrategy

Where/How do I handle different connection types using Repository Pattern with ADO.Net?

╄→гoц情女王★ 提交于 2019-12-13 17:24:16
问题 I am new to the repository pattern but am creating a repository to connect to two different database types that have the same data structure. Where and how should I handle the connection? Here are my requirements/constraints/project description I will be connecting to SQL Server 2005 and DB2 (on Iseries) I will be using the repository in a WPF application. Although I would like to use Entity Framework, I cannot. This is because IBM charges a rediculous $11,000 for a product called DB2 Connect

Shared repositories in repository pattern

走远了吗. 提交于 2019-12-13 12:09:19
问题 Repository dependency? Lets say I have a domain that looks like the following: public class User { public int UserId { get; set; } public Lazy<Post> Posts { get; set; } } public class Post { public int PostId { get; set; } public User Poster { get; set; } } A user with my posts. How do I set up my repository so that for every user , it returns a list of Post and for every post , I get the Poster ? I have 2 repositories: public class UserRepository : IUserRepository { public IQueryable<User>

Sorting and Paging on repository

被刻印的时光 ゝ 提交于 2019-12-13 10:17:22
问题 I have a simple ASP.NET MVC application which has possibility to search, filter and page a list of vehicle makes. I implemented sorting, filtering and paging on controller (on "Index" action) following the tutorials from kudvenkat on youtube https://www.youtube.com/watch?v=srN56uxw76s So, this is my "VehicleMakeController" and "Index" action: public class VehicleMakeController : Controller { private readonly IVehicleRepository _vehicleRepository; public VehicleMakeController() {

Repository pattern with EF Code First

北城余情 提交于 2019-12-13 06:16:07
问题 I am not grasping something when creating my repository pattern with EF Code First. If I want to abstract out EF I would have to make my repository be of type IObjectContextAdapter, no? That is what DbContext implements. If I later switch to use something like NHibernate or some other 3rd party ORM, it may not implement IObjectContextAdapter. Is my only solution to create a wrapper that wraps the ORM and does return an implementation of IObjectContextAdapter? If so, what is the point? 回答1: I

ASP.NET MVC: Repository pattern high concurrency updates

吃可爱长大的小学妹 提交于 2019-12-13 05:48:00
问题 I'm writing an app that we may be switching out the repository later (currently entity framework) to use either amazon or windows azure storage. I have a service method that disables a user by the ID, all it does is set a property to true and set the DisabledDate. Should I call to the repository, get that user, set the properties in the service, then call to the save function in the repository? If I do this, then thats 2 database calls, should I worry about this? What if the user is updating

Why does NHibernate need to know the ID of an auto ID based entity before flush is called?

陌路散爱 提交于 2019-12-13 05:40:29
问题 With my only ORM knowledge being L2S/EF, I was surprised when the following code inserted a row into the database before I called repo.Save: var repo = new UserRepository(); var user = new User { Name = "test" } repo.Add(user); //repo.Save(); Repo looks like this: public void Add(T entity) { session.Save(entity); } public void Save() { session.Flush(); } After some digging, it seems NHibernate needs to make the insert happen right away in order to get the ID of the new entity (since it's

IQueryable functionality, like Include, but for a single Entity?

谁说我不能喝 提交于 2019-12-13 05:35:56
问题 I'm using Entity Framework 6, and have implemented some semblance of the repository pattern. Initially, my repositories had functions like GetAll that returned an IEnumerable to avoid leaking the data layer abstractions out too much. But, my service layer, which is a wrapper around my repositories and contains business logic, needed more control over the queries. Control such as eager loading of related entities, selecting only certain columns, etc. So, in trying to avoid just exposing the

Question about Interfaces and DI?

折月煮酒 提交于 2019-12-13 04:52:10
问题 I am using the Service/Repository/EF/POCO pattern in a MVC app, and had a couple questions about the Interfaces. 1) Should I make an Interface per Service? 2) Should I make an Interface per Repository? Or, should I have a generic interface per layer (IService(Of T), IRepository(Of T)). What I dont understand is how in the controller say, it takes a IService(Of Category) interface in it's constructor, how do I implements the methods in the concrete class? Public Class HomeController Inherits

Does this Entity Repository Service example fit into Domain-Driven Design?

拟墨画扇 提交于 2019-12-13 02:49:09
问题 I would like to know if you find the following pattern meaningful in domain driven design. The domain layer consists of model and repository. The application layer consists of services that handles queries from the user interface, or from controllers in the Model-View-Controller pattern. Details of the structure: // Assembly Model: public class Phrase { public int PhraseId { get; private set; } public string PhraseText { get; private set; } public Phrase(string phraseText) { this.PhraseText =