repository-pattern

“The underlying provider failed on Open” Error when using EF5 Code First with Unity IoC in Azure Worker Role against SQL Azure

回眸只為那壹抹淺笑 提交于 2019-12-24 09:36:10
问题 I am using Entity Framework 5 Code First, I use the repository and unit of work pattern, and have my domain models, repositories, and service layer working fine within an MVC app running in a Windows Azure cloud service. I'm using Unity for IoC and inject repositories, controllers, and service classes as required, and use a per-request lifetime. It has been working great. However, when I use the same code/class libraries for the domain, repository, and the EF5 DbContext, in an Azure Worker

Mocking Context and Repository with UnitOfWork

半城伤御伤魂 提交于 2019-12-24 09:29:46
问题 I am building out unit tests for a small app we need to build. I have implemented the Repository / Unit Of Work pattern. My manager classes implement the unit of work pattern. For a given interface: public interface IUserManager { List<ApplicationUser> GetUsers(Expression<Func<ApplicationUser, bool>> filter = null); ApplicationUser GetUser(Expression<Func<ApplicationUser, bool>> filter); ApplicationUser AddUser(string username, List<string> environmentIds, bool isAdmin = false); void

Add simple business logic to repository in ASP>NET MVC 3 C#

巧了我就是萌 提交于 2019-12-24 07:27:14
问题 I have a question concerning an issue that has already been disputed many times in stackoverflow (I apologize for this) but no general answer has ever been given because of the subjectivity of the topic from one case to another: can we add business logic to the repository layer according to the repository pattern? I have an MVC 3 application with ViewModels (that means I don't use the ViewData at all). The model is an LinqtoSQL EF of course connected to a database. Currently I am accessing

Select specific columns from a repository in Doctrine 2

浪子不回头ぞ 提交于 2019-12-24 04:44:09
问题 First, we know that depending on the amount of columns in a query, may increase the response time. In Doctrine call the following store, which has a relationship and it brings all the columns of both entities. public function index() { $this->students = $this->model->getRepository()->findAll(); } But thinking about the statement that I gave earlier, the return of this repository is more time consuming than if it was a non-relationship? And other questions. Can I select the columns that I want

Why use database factory in asp.net mvc?

痞子三分冷 提交于 2019-12-24 04:23:18
问题 Recently I have worked with asp.net mvc and I have seen 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 dataContext; public EFMVCDataContex Get() { return dataContext ?? (dataContext = new EFMVCDataContex()); } protected override void DisposeCore()

ASP.Net 5 project referencing old class library

无人久伴 提交于 2019-12-24 02:10:50
问题 I was trying repository pattern with ASP.Net 5 project and service project. I referenced my " .Service" class library project into my " .Web" project but something went wrong with the reference. I removed all referenced to other libraries, even removed my " .Service" and " .Web" projects and added new empty ones but the newly created " .Web" project still referencing the old version of deleted " .Service" project. " .Web" > ASP.Net 5 project. " .Service" > .Net Framework 4.5.1 class library

How to include complex entity fields in a projected entity framework object?

好久不见. 提交于 2019-12-24 01:53:12
问题 I often use the System.Data.Entity.DbExtensions Include() method to cause complex entity fields to be included in query results from my repositories. However, when I project my entities into new classes, I seem to lose this "concretization" of included complex entity fields. For example, say I wanted to return an Event object from my repo, and be able to access the complex entity field Assessment : public class EventRepository { ... public IList<Event> GetEvents() { using (var context = new

Minimal Repository implementation using Entity Framework

大城市里の小女人 提交于 2019-12-24 00:23:19
问题 I'm trying to implement a minimal generic repository pattern in my application. I have a really small interface for querying and saving data: public interface IRepository { IQueryable<TEntity> Query<TEntity>() where TEntity: BaseEntity; void Save<TEntity>(TEntity entity) where TEntity : BaseEntity; } BaseEntity is a base class for all the objects I will store in my repository: public abstract class BaseEntity { public Guid Id { get; set; } public DateTime CreatedDate { get; set; } public

Proper way to dependency inject authenticated user to my repository class

隐身守侯 提交于 2019-12-23 17:36:04
问题 I am using a service layer with repository pattern. The controller has a dependency on the service layer, and the service layer has a dependency on the repository. I have to pass logged in user information to the repository layer for authorization purposes and am trying to determine the best approach for injecting the user information into the repository considering that I seem to have an extensive injection chain: controller -> service(s) -> repositories -> logged in user info. I guess the

Constructing a Domain Object from multiple DTOs

橙三吉。 提交于 2019-12-23 12:37:31
问题 Suppose you have the canonical Customer domain object. You have three different screens on which Customer is displayed: External Admin, Internal Admin, and Update Account. Suppose further that each screen displays only a subset of all of the data contained in the Customer object. The problem is: when the UI passes data back from each screen (e.g. through a DTO), it contains only that subset of a full Customer domain object. So when you send that DTO to the Customer Factory to re-create the