repository-pattern

How should the repository pattern update the ID of the object after a save to database method?

落爺英雄遲暮 提交于 2019-12-11 01:56:52
问题 After I create my POCO in memory, I call the Save method on the repository object. I need to then update the POCO with the database ID created during the save operation. Should I pass the object in using ref, simply have the save method return the ID and manually update the object from the calling page, or what? Here is some sample code: public GiftCertificateModel { public int GiftCerticiateId {get;set;} public string Code {get;set;} public decimal Amount {get;set;} public DateTime

Where should I put commonly used data access code with logic not fitting to Repository when using Service classes on top of Repository/UnitOrWork?

霸气de小男生 提交于 2019-12-11 01:39:31
问题 In my earlier question I was asking about implementing repository/unit of work pattern for large applications built with an ORM framework like EF. One followup problem I cannot come through right now is where to put codes containing business logic, but still lower-level enough to be used commonly in many other part of the application. For example here is a few such method: Getting all users in one or more roles. Getting all cities where a user has privileges within an optional region. Getting

Reposity pattern using linq

有些话、适合烂在心里 提交于 2019-12-11 01:21:57
问题 How can I implement the so called "repository pattern" that Rob Conery shows in [MVC Storefront][1] when I use two different generated linq codes? Do I need to implement a real repository pattern as Fredrik Normen discusses at What purpose does the Repository Pattern have?? The thing is that I want pass some of the nice features that LINQ provides from my "repository" so that I can use it later, so if not required I do not want to implement a real repository pattern as Fredrik discussed about

EF 4.1 DBContext AutoDetectChangesEnabled

天大地大妈咪最大 提交于 2019-12-11 01:17:00
问题 OK. I have turned off AutoDetectChangesEnabled, and when I query the context, modify an entity and attempt to save changes, nothing gets updated. I would expect that. But when I mark the entity as modified, I would expect it to change. Any ideas? I am using the UnitOfWork, Repository, Service pattern. If I enable AutoDetectChangesEnabled then all is fine. What is the standard way to persist changes to attached objects? What about detached objects? Thanks in advance, Sam 回答1: It's not just

Null Base UnitOfWork - EntityFramework With Repository Pattern - UserManager

北战南征 提交于 2019-12-10 21:48:30
问题 I am creating simple web api/ SPA application using EntityFramework, IUnitOfWork, Repository pattern, Unity DI along with Asp.net Identity. 1: Unity configuration public static void RegisterTypes(IUnityContainer container) { // TODO: Register your types here container.RegisterType<DataContext>(new PerResolveLifetimeManager()); container.RegisterType<IUnitOfWork, UnitOfWork>(new PerResolveLifetimeManager()); container.RegisterType<IUserStore<User, Guid>, UserRepository>(new

“No property found for type” combining repositories spring-data-neo4j

霸气de小男生 提交于 2019-12-10 21:17:23
问题 I'm using spring-data-neo4j and I'm trying to combine repositories to be able to use custom ones. I think I've followed correctly the nomenclature conventions specified in 20.8.7 Creating repositories and other SO questions like this. Anyway, I'm doing something wrong because I'm getting this exception message Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property someCriteria found for type User! User entity @NodeEntity

Implementing Generic Repository using Entity framework code first

若如初见. 提交于 2019-12-10 19:33:48
问题 I'm experiencing my first try on implementing Generic Repository Pattern and Unit of framework. I'm not using MVC on the project in hand. Please take a look at this method included in Generic Repository class: public virtual IEnumerable<TEntity> Get( Expression<Func<TEntity, bool>> filter = null, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null, string includeProperties = "") { IQueryable<TEntity> query = dbSet; if (filter != null) { query = query.Where(filter); } foreach

scafford auto generate crud repository asp.net5

自作多情 提交于 2019-12-10 19:05:52
问题 Hi I am using visual studio 2015, I understand that we can generate crud view controller and action by adding new scafford item. But the code generation is not very usable seem all the data layer is depend on the controller So Here is my question is tat any way to use scafford generate the code which also generate the repository pattern also? Or any nuget which offer the same feature? Sorry. I had googling few hour . But still cant find the solution. :( Thanks 回答1: I agree, that it's a

Using Entity Framework with repository pattern in WinForms MDI

独自空忆成欢 提交于 2019-12-10 14:22:30
问题 We are about to start up a new project similar to a previous one. I could just copy the old design but I am not all too satisified with the old design. It is a "standard" business system (sales,stocktaking,warehousing etc) built ontop of .Net 3.5 (Winforms MDI) with Entity Framework in the backend. All forms inherit from a baseform (which inherits Windows.Form). The form exposes a property called ObjectContext, which on the first call instantiates a new ObjectContext. This makes up a pretty

Generic Repository with Soft Delete Feature

陌路散爱 提交于 2019-12-10 14:19:13
问题 I have a generic repository implementation. I'm using asp.net mvc c#, code first entity framework. I created an interface named ISoftDelete: public interface ISoftDelete { bool IsDeleted { get; set; } } I implemented Delete and GetById in my base repository as follows: public virtual void Delete(T entity) { if (entity is ISoftDelete) { ((ISoftDelete)entity).IsDeleted = true; } else { dbset.Remove(entity); } } public virtual T GetById(long id) { T obj = dbset.Find(id); if (obj is ISoftDelete)