repository-pattern

Setting up a repository pattern in MVC

北战南征 提交于 2019-12-09 15:29:17
问题 I'm trying to figure out how the Repository pattern works and how it can be implemented in a custom MVC pattern. As far as i understand it, the Repository is a layer which simply returns data from an entity class or saves the entity class to a persistent layer. Now i currently see it like this: A request comes in into my controller to create a user. Just a username and password. My controller will do something like this: function CreateAction ( ) { $userRepo = new userRepository ( ); $user =

Setting the identity of a Domain Entity

我们两清 提交于 2019-12-09 13:42:24
问题 All entities in the domain need to have identity. By inheriting from DomainEntity , I am able to provide identity to classes. City domain entity (stripped down for easy reading): public class City : DomainEntity, IAggregateRoot { public string Name { get; private set; } public Coordinate Coordinate { get; private set; } public City(string name, decimal latitude, decimal longitude) { Name = name; SetLocation(latitude, longitude); } public City(string name, decimal latitude, decimal longitude,

Not finding .Include() method in my EF implementing Generic repository

瘦欲@ 提交于 2019-12-09 11:39:54
问题 I am using Generic repository to wrap DbContext and DbSet classes from upper level. However, when in certain queries I need to use ".Include()" method to include navigation properties. But I am unable to find these methods on repository methods returing IQueryable Like, this.repository.GetQuery<GeneralCalendarDates>() this doesn't have include method, though I can use .ToList() here. Any idea what could be wrong here? 回答1: Include for IQueryable<T> is an extension method that is implemented

There is no argument given that corresponds to the required formal parameter 'context of GenericRepository<Incident>.GenericRepository(dbContext)

依然范特西╮ 提交于 2019-12-09 07:57:11
问题 I am getting this error message which when trying to inherit from my GenericRepository. The error says I need to also provide a context but I am not sure how? //IncidentRepository public class IncidentRepository : GenericRepository<Incident> //Generic Repository (to inherit from) public class GenericRepository<TEntity> where TEntity : class { internal db_SLee_FYPContext context; internal DbSet<TEntity> dbSet; public GenericRepository(db_SLee_FYPContext context) { this.context = context; this

Generate identity for an Oracle database through Entity Framework using an exisiting stored procedure

China☆狼群 提交于 2019-12-08 21:38:44
问题 How to automatically generate identity for an Oracle database through Entity Framework? I have a function that I could call and generate the column which is not in the context how do I explicitly call the stored procedure through Entity Framework? I am using a repository pattern. Random Number generator to insert a record (where I get the primary key through a UDF and pass this to the entity to insert). 回答1: 1) Create sequence in Oracle CREATE SEQUENCE dummy_test_seq MINVALUE 1 MAXVALUE

Call methods between repositories - Repository Pattern

北城余情 提交于 2019-12-08 19:25:29
问题 I'm using the Repository Pattern (like the examples in the http://www.asp.net/mvc site) in a ASP.NET MVC application. I have two repositories, one called CategoryRepository an other called ProductRepository. I also use two services, the CategoryService and ProductService to validate and call the repositories methods. I need a list of categories in ProductService, a method that return one is already implemented in the CategoryRepository. My question is, which is the correct way to call the

Generic repository implementation with EF

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-08 19:10:37
For a simple repository public interface ISimpleRepository<T> { IApplicationState AppState { get; set; } void Add(T instance); void Delete(T instance); void Delete(Guid rowGuid); IQueryable<T> GetAll(); T Load(Guid rowGuid); void SaveChanges(); void Update(T instance); } my implementation of the Load() method for specific repository for class Product might look like this: public Product Load(Guid rowid) { return (from c in _ctx.Products where c.id == rowid select c).FirstOrDefault(); } Now this is assumed when my repository implementation class looks like this: public class

How to force EF LINQ query generation without execution

百般思念 提交于 2019-12-08 17:37:28
I have a nicely decoupled app and dependency-injected app that uses Entity Framework 4.1 CodeFirst to expose IQueryable through a repository pattern. It's easy enough to mock the underlying datastore when testing the repository clients, however a certain class of bug is not being caught: The repository clients are free to layer their own LINQ predicates, joins, etc on top of what the repository returns: { _myRepository.FindAll().Where( x => x.Id == 3 && SomeMethod(x.Name) == "Hello" ); } This kind of query will succeed in a unit test that mocks _myRepository, because mock returns an in-memory

Aggregate roots. How far does the rabbit hole go

家住魔仙堡 提交于 2019-12-08 17:26:16
问题 I'm trying to use the Repository pattern for my current project and i'm currently in the process of trying to model the domain and find the aggregate roots. I've read of the 'Cascading Delete' rule which states that if it doesn't make sense to delete a member when the root is deleted then it shouldn't be part of the root. I'll use a Police incident as an eample :- Incident (Aggregate root) - This could contain investigating officers, notes made by each officer. It could also contain suspects

How to manage client context object in seperate class library?

守給你的承諾、 提交于 2019-12-08 16:44:00
问题 I am trying to create a library(class library) for sharepoint which will have all sharepoint dll to interact with sharepoint server to upload files,documents and create document library and document set . Now this library could be consumed by clients like web application(asp.net webform or mvc) or console application or web api/wcf services or windows form anything. So here I am bit confused with creating repository patterna and unit of work layer in order to manage client context object. I