repository-pattern

Implement WCF Data Service using the Repository Pattern

六眼飞鱼酱① 提交于 2019-12-12 08:57:20
问题 We are using the repository pattern in our ASP.NET MVC 3 application. This means that, although we use EF 4.1 Code First to access the data in the backend, all MVC controllers do that via a generic repository class rather than directly over the DbContext subclass. Simplified code snippet: public class MyEntityContext : DbContext, IMyEntityContext { public IDbSet MyEntities { get; set; } ... } public class MyEntityRepository : IMyEntityRepository { private IMyEntityContext _context; public

What is the best way to build view model?

拟墨画扇 提交于 2019-12-12 08:05:54
问题 I'm using asp.net mvc with entity framework and starting to learn DDD. I'm working on project that contains surveys. Here's my domain model: public class Survey { public int? SurveyID { get; set; } public string Name { get; set; } public decimal MinAcceptanceScore { get; set; } public int UserFailsCount { get; set; } public IEnumerable<SurveyQuestion> Questions { get; set; } public IEnumerable<Prize> Prizes { get; set; } public IEnumerable<SurveyAttempt> UserAttempts { get; set; } } I need

Domain Driven Design (Linq to SQL) - How do you delete parts of an aggregate?

筅森魡賤 提交于 2019-12-12 07:59:40
问题 I seem to have gotten myself into a bit of a confusion of this whole DDD\LinqToSql business. I am building a system using POCOS and linq to sql and I have repositories for the aggregate roots. So, for example if you had the classes Order->OrderLine you have a repository for Order but not OrderLine as Order is the root of the aggregate. The repository has the delete method for deleting the Order, but how do you delete OrderLines? You would have thought you had a method on Order called

AutoFac does not register api controller

限于喜欢 提交于 2019-12-12 06:15:34
问题 I am using AutoFac to registered api controller but don't know whats the problem Getting error Type 'myApp.WebAPI.Controllers.myController' does not have a default constructor I added IocHelper class as below public class IocHelper { public static IContainer CreateContainer() { var builder = new ContainerBuilder(); builder.RegisterControllers(Assembly.GetExecutingAssembly()); builder.RegisterApiControllers(Assembly.GetExecutingAssembly()); var container = builder.Build(); DependencyResolver

Implementing this generic repository, unit of work and repository factory

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 05:59:20
问题 I have modifed this a bit, removed one method, from the original post where I found this example. Here is the generic repository. /// <summary> /// Repository base class used with DbContext Originally From http://dotnetspeak.com/index.php/2011/03/repository-pattern-with-entity-framework/ /// </summary> /// <typeparam name="TContext">Type of DdContext that this repositiory operates on</typeparam> public class RepositoryBase<TContext> : IDisposable, IRepositoryBase where TContext : DbContext,

How would I pass a constructor parameter at runtime to my dbContext and also register them with Unity as such

两盒软妹~` 提交于 2019-12-12 05:44:33
问题 I am trying to implement all sorts of good stuff like UnitOfWork, Repository, DI. I am using Unity for DI. Here is my dilemma. I have a few (currently 3) databases with identical schema but obviously with different data for business reasons (I will call them GroupDB1, GroupDB2 and GroupDB3). I also have a Master Database (DifferentDB) that has a different schema. My dbcontext need to use different databases for different scenarios at runtime. I have no clue how to put them all to work

Asp.net MVC 2 Entity Framework Generic Repository method. How to update a specific column?

南笙酒味 提交于 2019-12-12 05:37:49
问题 I have 10 tables with the same design. Each of them have an IsActive column. For example: Category CatID CatName IsActive Product PrdID PrdName IsActive Is there a way to create a generic method to update the IsActive column. public void Deactivate<T>(T TEntity) { // Put the code to update // IsActive } I read about generic repository, but nothing explains how to update a specific column. Thanks everyone. 回答1: The trick is to put a where type restriction for your generic type on your

Unable to cast object of type 'DBContext.Models.Contact' to type 'System.Data.Entity.Infrastructure.IObjectContextAdapter'

独自空忆成欢 提交于 2019-12-12 04:34:53
问题 I am trying to implement "Repository-Pattern" and "Edit" method in Contact-Controller is making use of "Attach Method" in Contact-Repository is throwing Error. Additional information: Unable to cast object of type 'Contacts.Models.Contact' to type 'System.Data.Entity.Infrastructure.IObjectContextAdapter'. Before This issue i faced another issue of ObjectStateManger Extension not found error in the code : entities.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified); So i had to

applying unit of work in a generic repository

删除回忆录丶 提交于 2019-12-12 04:05:34
问题 I'm learning on doing repository with unit of work. I also know how to do DI/IOC. But my problem is I can't figure out where to apply Unit of Work in my code. Below is a Generic Repository. public abstract class Repository<T, C> : //IDisposable, IRepository<T> where T : class where C : DbContext, new() { private C entities = new C(); public C Context { get { return this.entities; } set { this.entities = value; } } public virtual void Insert(T entity) { this.entities.Set<T>().Add(entity); } //

Repository and UoW pattern with service layer

半世苍凉 提交于 2019-12-12 03:40:00
问题 I'm using Repository and UoW pattern. My services look like this: public class MyService : IService { private readonly IUnitOfWork<MyContext> unitOfWork; private readonly IMyRepository myRepository; public MyService(IUnitOfWork<MyContext> unitOfWork, IMyRepository myRepository) { this.unitOfWork = unitOfWork; this.myRepository = myRepository; } //Methods... } Within services, I need to use other entities (for example to check for rights, etc). Is it recommended to use the relevant