Menu
  • HOME
  • TAGS

Using the repository pattern, how do I reference my domain models without creating a leaky abstraction?

c#,entity-framework,repository-pattern

The repository sits at the bottom of my stack and currently contains my domain models That's your problem, the repository uses domain entities, but it doesn't contain them. The repo is part of the persistence, your domain model should be part of the Domain layer. The repo interface is...

Entity Framework 6 , Should I use repository pattern?

entity-framework,entity-framework-6,repository-pattern

First of all trying to treat your DbContext as singleton object is a bad idea, because you can't manage transactions in your operations. you have to instantiate your DbContext per operation. Second, try to separate your "Data layer concerns" from your "Business concerns". for example : One method for :...

OOP Pattern with methods calling Repositories

php,oop,symfony2,doctrine,repository-pattern

it's like a basic application service in a typical layered architecture. Application Services : Used by external consumers to talk to your system (think Web Services). If consumers need access to CRUD operations, they would be exposed here. ...

Asp.Net MVC and Strategy pattern

asp.net-mvc,entity-framework-6,repository-pattern,strategy-pattern

Your unit registrations and classes look a little off. From what I can gather, this is what you really want to do. Setup a factory that will determine at runtime which IAuthStrategy should be used: public interface IAuthStrategyFactory { IAuthStrategy GetAuthStrategy(); } public class AuthStrategyFactory { readonly IAuthStrategy _authStrategy; public...

IQueryable in Repository

c#,entity-framework,repository-pattern

Its completely OK to use anything for private implementation. It does not exposed to the clients of your repositories via API, so it does not affect them in any way. Actually clients of repositories should depend only on repository abstraction (interface usually). So even public members which are not part...

How much repository interfaces must created in Repository Pattern?

java,c#,design-patterns,repository-pattern

There is no must . You create as many as the app needs.You could have a repository interface for each business object and a generic interface. Something like interface ICRUDRepo<T> //where T is always a Domain object { T get(GUid id); void Add(T entity); void Save(T entity); } //then it's...

MVC controller giving me strange situation when passing model to controller

c#,visual-studio-2013,asp.net-mvc-5,repository-pattern

Add a hidden field within BeginForm() for your model.Id @Html.HiddenFor(model=> model.Id) ...

Modern ORM vs Repository/IoW pattern

entity-framework,nhibernate,orm,repository-pattern,unit-of-work

Personally i think your approach is solid. But equally Im surprised you see this approach as very different to the repository / Unit of Work Pattern. Your IService layer is directly comparable to a basic Unit of Work layer combined with a repository layer implemented via an interface. The repository...

Telerik OpenAccess generating the same query for every function call

c#,sql,telerik,repository-pattern,openaccess

I believe you are victim of a subtle difference between definitions of LINQ extension method - in-memory ones use Func<> while SQL-bound use Expression<> as parameter type. My suggestion is to change All(Func<TEntity, bool> x=null) to All(Expression<Func<TEntity, bool>> x=null)

Injecting Fake Data with Unity DI

mocking,unity,repository-pattern

This is a very common scenario that lot of developers come across. You using DI. So one of the most important thing is that you should be able to configure your container to resolve a Fake implementation until the real service is ready. As you have mentioned UI dev can...

Automapper missing type map configuration or unsupported mapping

entity-framework,mongodb,automapper,repository-pattern,nuget-package

You are most probably missing configuration for Author classes. I assume, you also have ME.Book.Author and DE.Book.Author, so you have to provide configure mapping also between these two classes. Extend configuration like this: public static void SetAutoMapperConfiguration() { // fix namespaces and optionally provide mapping between properties Mapper.CreateMap<ME.Book.Author, DE.Book.Author>(); Mapper.CreateMap<ME.Book.Book,...

architecture layering and unit of work pattern

architecture,repository-pattern,unit-of-work

There is many concepts in your question that don't relate only to the technical part. I've been there trying to solve it technically but this always fails in the long run. What is important is also what a business expert have to say. This is where Domain Driven Design shines...

Use viewmodel to bind data with html.dropdownlistFor in asp.net-MVC

c#,asp.net-mvc,repository-pattern,html.dropdownlistfor,model-view

@Html.DropDownList("Group", new SelectList(Model.Groups.Select(g => g.GroupName ))) ...

Constructor Injection pattern using C# and Autofac

c#,dependency-injection,repository-pattern

Have you registered DbContext with your container? From the error message it looks like the problem is with resolving the dependencies for CountryRepository that is the problem. All dependencies for classes registered in the container must be registered with the container. How can the container create an instance of CountryRepository...

.NET MVC Service layer constructor

asp.net-mvc,constructor,repository-pattern,unit-of-work,service-layer

Constructors in C# Given your code public TownService() : this(new UnitOfWork()) { //1 } public TownService(IUnitOfWork unitOfWork) { //2 _unitOfWork = unitOfWork; } Invoking new TownService() will Call the parameterless-constructor Instantiate a new UnitOfWork and call the overload TownService(IUnitOfWork unitOfWork), so //2 is executed. This happens because of the this(...)...

Repository Pattern can be used with webapis?

design-patterns,repository-pattern

The whole point of programming to an interface is that you should be able to substitute one implementation with another implementation without changing the correctness of the system. This is also known as the Liskov Substitution Principle. Thus, if you were to rename your interfaces based on a concrete implementation,...

Inject parameter into spring-data dynamic query-build methods

java,spring,spring-data,repository-pattern,query-builder

Currently there's no direct support for that. Spring Data JPA already has support to use SpEL expressions in manual query definitions so that e.g. Spring Security specific functions can be used to in JPQL queries. This is shown in this example project but requires manual definition of the queries. We're...

Entity Framework Repository Pattern - Database Catalogs

entity-framework,entity-framework-4,repository-pattern,unit-of-work

Yeah, don't use this anti pattern (generic repository wrapping DbContext while exposing EF entities). If you really want to use the Repository make the repository interface return ONLY business (or view models if it's a query repo) objects, never IQueryable or other details exposing EF or whatever are you using....

Using MVC + Repository Pattern, where Business Logic should be?

c#,asp.net-mvc-4,repository-pattern,unit-of-work,business-logic

The short answer - it depends. If it's a fairly complex or sizable application, I like to create a service layer project with the repositories as dependencies. If it's a small application, I'll put the logic in the controller. In my opinion, if it takes more time and effort to...

Access Laravel BaseController Property

inheritance,laravel,controller,repository-pattern

If you do like this it will work: The user repository: class UserRepository { public function getProp() { return 'user prop'; } } The Base Controller class BaseController extends Controller { protected $user; protected $prop; public function __construct(UserRepository $user) { $this->user = $user; $this->prop = $this->user->getProp(); } } The FooController...

Should concrete service depend on concrete repository or interface?

c#,entity-framework,dependency-injection,repository-pattern

I always go with repository interfaces. First reason is testability - DbContext and DbSet<T> are hard to mock. So, unit-testing of services becomes really hard, if even possible. Second reason is IQueryable<T> being exposed by EF. It makes data-access logic spread over whole application, which violates SRP and makes fixing...

How to deploy solution from Visual Studio with multiple projects to Azure

azure,visual-studio-2013,asp.net-mvc-5,repository-pattern,web-deployment

Turns out something was wrong with my repository pattern and unit of work i redid the patterns again from scratch and it works

Why is my C# Inheritance not working with the Generic Repository Pattern

c#,asp.net-mvc,repository-pattern

DeleteRepository contains the Read method, as it inherits from ReadRepository. The issue is you're local variable is of type IDeleteRepository<Course> - this is no Read method on IDeleteRepository<Course>. If you changed your declaration to the correct type, you would have access to both methods: DeleteRepository<Course> deleteRepository = new DeleteRepository<Course>(new DbContext("SchoolDemoEntities"));...

Proper way to setup MVC project structure that won't have any dependencies [closed]

asp.net,asp.net-mvc-5,ninject,entity-framework-6,repository-pattern

It might be difficult to test your bll if if you can't mock the objects within the dal, so using interfaces and di would be useful in my opinion. You also have the option of swapping out your dal for a different dal if you loosely couple it. The interfaces...

Using Doctrine's EntityManager in a repository design

php,doctrine2,zend-framework2,repository-pattern

There are several ways to do this, of course. The typical way you'd do this kind of thing in a ZF2/D2 project would be to start with DoctrineORMModule. That module exposes Doctrine's EntityManager via the ZF2 Service Manager in a variety of handy ways (you can $sm->get('doctrine.entitymanager.orm_default') to explicitly get...

ASP.NET MVC Details view with many display fields but a single editable field

asp.net-mvc,entity-framework-6,repository-pattern,asp.net-mvc-viewmodel

So I solved this by ensuring that the primary key field PersonID is included in the View. I didn't think I needed it originally because it started off as a read-only Details view, and PersonID wasn't needed to be displayed. But when posting data back, I needed to add it...

IEntity where Key/ID type unknown

c#,repository-pattern

you could use Generics to make it strongly typed based on your situation. Ex., namespace Test.Database { public interface IEntity<T> { T KeyValue { get; set; } } } ...

Refactoring code using Entity Framework 6 to follow TDD [closed]

c#,asp.net,asp.net-mvc,entity-framework,repository-pattern

This is what I would do: Implement a repository for each entity in the context. If you have a set of similar operations that are done to all entities (for example, GetAll, GetByID, Create, Update, Delete), you could define a common interface which will be your starting point. Then, all...

Use multiple conditions in join LINQ. i,e AND

c#,asp.net-mvc,linq,entity-framework-6,repository-pattern

You only need to add a condition to filter the users that belong to the group 4. Try this: _listedUsersByGroupID = (from _user in _uow.User_Repository.GetAll() .Include(s=>s.UserInGroup.Select(r=>r.Group)) where user.UserInGroup.Any(ug=>ug.groupID==4) select _user).ToList(); ...

Architectural decision regarding Repository pattern (it is using Automapper)

entity-framework,architecture,automapper,repository-pattern

So the answer is simple. Bit of a silly question to begin with. The declaration for IRep was wrong. BaseRep<T,U>:IRep<T> instead of IRep<T, U>. The rep interface should be: public interface IRepository<T> where T : class { void Insert(T model); IEnumerable<T> GetAll(); } The base repository should be: public class...

Generic Repository for SQLite-Net in Xamarin Project

xamarin,repository-pattern,sqlite-net

This is an old question but here is my implementation. I´m using async connections as they provide better performance in mobile projects. The nuggets I installed are Sqlite.Net-PCL and Sqlite.Net.Platform.XamarinAndroid on the Android project (there´s another one for ios), and SQLite.Net.Async-PCL on the Core project. My Repository looks like this:...

DDD Repository: Use DAO for separation?

domain-driven-design,repository-pattern,dao

You are actually asking quite a number of questions here so I'll try to keep the answers as terse as possible :) Repositories return an Aggregate Root or an Entity. Some are quite adamant that repositories only return ARs and that is fine and will always suffice. There are two...

Repository and two context

c#,asp.net-mvc,entity-framework,repository-pattern

You should be injecting your ObjectContext into your repository instances, this way you can inject the same instance into both repositories and avoid the error. If you are using an IoC container it should allow you to specify the scope of instances it creates. If you are using Autofac, you...

Why repository pattern is extensively used in entity framework as though it is complex?

c#,asp.net-mvc,entity-framework,repository-pattern,nopcommerce

To provide a code example of why Approach 1 is better consider a test scenario. With Approach 2, when you call the Insert method in a unit test you will actually be calling: Controller.Insert > MyBal.Insert > Database execution. This is not what we want in unit testing. In unit...

breeze with asp.net web api, reporitories and UoW

mobile,asp.net-web-api,breeze,repository-pattern,unit-of-work

1) No you cant use breeze contextProvider.SaveChanges() in your other controllers. contextProvider.SaveChanges(JObject saveBundle) breeze server side expects saveBundle to be a json data created by breeze client side js. 2) Create any other webapi controller for REST with its own repository. You can't work with breeze's repository saveChanges without breeze...

Should a service access other services or just repositories?

c#,repository-pattern,unit-of-work

I wouldn't write the cancelling logic twice. Where you have it is up to you, but given your current structure, I'd inject ICustomerService into BatchService. So class could look something like public class BatchService : IBatchService { public ICustomerService<Customer> CustService { get; set; } public void CancelOrders(params int[] orderNos) {...

Why use database factory in asp.net mvc?

asp.net-mvc,repository-pattern

This is an example of an Abstract Factory design pattern. The idea is to create a seam to provide loose coupling between the classes so another type of context could be swapped, either for testing purposes or to extend the application. Generally speaking, a factory is a way to manage...

how to setup mock object for dynamic linq

unit-testing,mocking,moq,repository-pattern

Reproducing the solution the asker found themselves. The problem occurs when you use one of the overloads of Returns which takes in a Func delegate. That Func must either take zero parameters (i.e. a Func<TResult> where TResult is known at compile-time to be IQueryable<DomainObject> in your case) or take the...

What are the advantages of having Entity Objects separated from Domain Objects?

java,design,domain-driven-design,repository-pattern

Repositories should return domain objects, more precisely Entities (the DDD sort), and more precisely Aggregate Roots, most of the time, because their consumers need to ask aggregates to do things. One popular way to keep the Domain isolated from infrastructure and persistence concerns is to declare Repository interfaces in it,...

Injecting/Managing at runtime changing connectionstrings using Entity Framework, Dependency Injection, Unit of Work and Repository Patterns

entity-framework,dependency-injection,repository-pattern,autofac,unit-of-work

Your on the right track, I have used var mtc = new MultitenantContainer(container.Resolve<ITenantIdentificationStrategy>(), container); DependencyResolver.SetResolver(new AutofacDependencyResolver(mtc)); The identification strategy would be based on the logged in user. With defaults for when they aren't logged in. public class CompanyNameIdentificationStrategy : ITenantIdentificationStrategy { public bool TryIdentifyTenant(out object tenantId) { var context =...

To Repository or Not To Repository

c#,entity-framework,dependency-injection,domain-driven-design,repository-pattern

"Depository" lol.... Anyways, you got right the bit that you don't want the domain coupled to EF that's why the T in your repository interface should be domain aggregate root and NOT an EF entity (or a 'domain' object designed to work properly with EF). Your Domain layer is never...

Accessing repository pattern through one more layer called service in Laravel

laravel,service,laravel-5,repository-pattern

When you access class variables, you need to do $this->some_var, not $this->$some_var. In the latter case, PHP thinks you're trying to use the string value of $some_var, and it can't - so that's why it's complaining about not being able to convert to string. Just changing that should work right...

Restrict Operations On Database Through Repository

c#,linq,entity-framework,repository-pattern

I would argue that you are worried about restricting operations at the wrong layer; the Repository. Assuming your Repositories are supposed to abstract away the details of your DB and Entity Framework, I think this is too low of a level to do what you want. If you have a...

Pass list value to view model class variable in ASP.NET MVC

c#,asp.net-mvc,repository-pattern,asp.net-mvc-viewmodel

I would have done it a little different. You want to return a single view model to the view consisting of a list of users and a list of groups (please correct me if I am wrong). I would have initialised the lists to empty (containing no items) in the...

Entites count in dependency injection and Repository Pattern

asp.net,asp.net-mvc,dependency-injection,repository-pattern

The answer is: it depends. If your application is small, with two entities in a single database, and you do minimal transformation or validation work on save, I would say you should only have one repository class for access to both entities. This minimizes complexity. However if you need to...

Queries on Repository Layer in MVC application

asp.net-mvc,repository-pattern,poco

Usually, the Repository is the method of accessing the data and is therefore just an implementation technique of the DAL. I'd combine them both as the DAL. In terms of other models, I assume you mean the classes that correspond with your data items. These should also live in...

How to maintain data after DbSet.Remove?

c#,entity-framework,entity-framework-6,repository-pattern

You have to understand that two processes are going on: Entity Framework keeps track of the entities that are loaded in DbContext, maintaining their state as Added, Modified, Deleted or Unchanged. You can check this with a MyDataContext.Entry(MyEntity).Statecall. Outwardly the POCO classes behave just like you would expect from classes...

Fetching records taking some time using repository and dependency injection

asp.net-mvc,dependency-injection,repository-pattern,autofac,unit-of-work

Without looking at the view it is hard to say where your delay is. There are several things to consider: DI consume virtually no time here, so do not blame it When using ORMs, always pair it with a profiler like EF Profiler from Hibernating Rhinos or DevArt. See SQL...

How to fully charge a business entity in a service layer

asp.net-mvc,domain-driven-design,repository-pattern,n-tier-architecture,ddd-repositories

This is probably best suited for CodeReview, but here are a few thoughts that may save you some trouble : Having a whole separate DAL object model might be overkill. Most modern ORMs will take care of the domain objects/DB mapping for you without polluting your domain model with persistence...

Using MVC5 Repository pattern but need advice on where to put business logic

asp.net-mvc-5,entity-framework-6,repository-pattern

Ideally you want to separate your actual business logic from your entities and abstract it away from your database or ORM as much as possible by creating a business logic layer and injecting your repository into your service/business logic layer using an IoC container and dependency injection. The common approach...

Linking entities with repositories

c#,asp.net-mvc,entity-framework,asp.net-mvc-4,repository-pattern

Make customer list a child of user: then you can pull / map the list within your customer service. Start by adding CustomerList to you user ViewModel: public class UserModel : IUserModel { private ICustomerService _customerService; public UserModel() : this(new CustomerService()) { } public UserModel(ICustomerService customerService) { _customerService = customerService;...

What category is repository pattern in?

oop,design-patterns,repository,repository-pattern

Repository can be viewed as a special kind of Façade (structural) but also as a special kind of Factory (creational). Also, as the Repository often expose collection-like interface, then it might be a special application of Iterator (behavioral). What I am trying to say is that neither those categories nor...

Unable cast d__3a`1[System.Object] to type System.Collections.Generic.IEnumerable

c#,csv,generics,repository-pattern

Try following - repository.InsertAllOnSubmit(list.Take(100).Cast<Activity>()); Cast extension method lets you cast enumerables from one type to another (Assuming of course that the cast is valid.. which is what you expect with explicit casts)....

How to use Repository and Unit of Work Patterns with ADO.NET?

asp.net-mvc,design-patterns,ado.net,repository-pattern,unit-of-work

I've written a blog post which teaches you on how to write driver independent code and how to implement Uow/Repository pattern with plain ADO.NET. It's a bit too long to include in this answer, but basically the IDbtransaction will represent your Unit oF Work (or be contained in one) and...

Laravel Eloquent Relationships with Repository/Service Design Pattern

php,laravel,eloquent,repository-pattern,service-layer

You have two classes with the same name in the same namespace. Use different namespaces so you can use the same class names. I usually use \Models to locate my models classes. At the top of each model file: namespace Models; In your controller or any part of your app:...

Performance Issues with Include in Entity Framework

json,entity-framework,repository-pattern,asp.net-web-api2,poco

The performance has been improved by Enabling Lazy Loading.

Implement EntitySet as IList

c#,linq,repository-pattern

The return type of the implementation of the interface must match the return type declared in the interface. This is called return type covariance and it is not supported by C#. So the code below doesn't work even though List implements IList public interface IFoo { IList<string> Foos {get; set;}...

What is a better more testable way for Repository based on tenants

c#,unit-testing,design-patterns,repository-pattern

+1 on zaitsman's comment. You seem to already have a nice seam in place that allows testing MyRepository in isolation. If a) IDataAccess is an interface and b) your GetClientsForTenant method uses it internally, you can provide a fake IDataAccess that returns precooked fakeClients and you will be able to...

applying unit of work in a generic repository

c#,asp.net-mvc,asp.net-mvc-4,repository-pattern,unit-of-work

We saw together you should separate your service from your repository. Here, your problem seems to come from the fact you use two different dbcontext instances. one in your repository and one in your UnitOfWork. Instead, you should inject the same Dbcontext instance in your repository and your UnitOfWork. EDIT:...

Updating records using a Repository Pattern with Entity Framework 6

c#,asp.net-mvc-5,entity-framework-6,asp.net-identity,repository-pattern

Ok, I figured this out. The reason why there's no Update in new repository patterns (Entity Framework 6) is because there's no need for one. You simply call your record up by id, make your changes and then commit/save. For example, this is my edit POST method from my postController:...

Repository pattern: DAL or BLL [closed]

c#,repository-pattern,business-logic,bll

The repository patterns responsibility is to store and fetch data from the data layer and to make abstraction about how this data layer looks like. The idea behind it is that if this underlying layer should change, you would possibly need to change the implementation of the repository but not...

PHP How should Repositories handle adding/removing/saving/deleting entities?

domain-driven-design,repository-pattern,ddd-repositories

I've been developing using DDD techniques for around 6 months now and always use the save and delete methods, the save should persist the data to your persistence layer, the delete should remove from your persistence layer. Saying the above, there is no reason why it shouldnt add to your...

Updating navigation properties that are collections in Entity Framework with Repository pattern

c#,entity-framework,repository-pattern

Yes there is a better approach. For a new person, use: _context.People.Add(myPerson); //myPerson can have Pets attached This will traverse all sub objects and mark them as NEW. When updating person, after calling the above code, you need to set which pet objects are modified/deleted. I learned this in a...

Unit Of Work in Generic Repository

c#,asp.net-mvc-4,repository-pattern,unit-of-work,onion-architecture

Managing transactions in the repository is definitely not the standard way to do it, as it removes the possibility to implement business logic that spans multiple repositories (or multiple actions on the same repository) and is required to be executed atomically. I would try to keep the transaction management on...

Where to put the method. Service layer ( BL ) over repository?

c#,asp.net-mvc,architecture,repository-pattern,service-layer

In general repository should encapsulate only the logic of accessing database (initialization of context, transactions, connections and etc.). It is very common to create a generic CRUD repository and reuse it for all your business entities. All the business related logic should be placed in business layer(service layer). The major...

Do you place files processing logic in repositories? (Using generic repository and UoW pattern with EF)?

c#,.net,entity-framework,repository-pattern

So here is my question. Where does the logic for loading file data into EF entities belong? My opinion is that it belongs in your repositories. Your data-stores aren't always going to be databases. They can be files, internal and external services, excel sheets, etc. Should I make this...

How to decouple eloquent from the service layer?

laravel,eloquent,repository-pattern,service-layer

The easy way: public function assignToAuthor($postId, $authorId) { $post = $this->find($postId); // or whatever method you use to find by id $post->author_id = $authorId; } Now, the above implies that you know the foreign key author_id of the relation. In order to abstract it just a bit, use this: public...

Visibility of inherited class methods does not make sense?

c#,entity-framework,inheritance,repository-pattern,unit-of-work

unitOfWork.FieldRepository has type IFieldRepository so only GetAllFields() is visible: IFieldRepository repository = unitOfWork.FieldRepository; repository.GetAllFields(); You need either cast it to EFGenericRepository<Field>, IFieldRepository (don't do it!) or add this method to the interface: public interface IFieldRepository { void Insert(Field entity); } Being virtual doesn't make any difference here, you can remove...

Why do Examples of the Repository Pattern never deal with Database Connection Exceptions?

architecture,exception-handling,repository-pattern

I honestly think that it isn't addressed because of the ongoing (and emotional) debate about what to do with exceptions. There is a constant back and forth over whether exceptions should be handled locally (where there is a greater chance of understanding them and doing something intelligent, like retrying) or...

Where to place multiple queries for repository

c#,design-patterns,repository-pattern

Generally, your logic that makes decisions based on business rules goes in the service layer. The code that creates, updates, or deletes rows from tables (the standard CRUD functions) goes into the repository. So if you need to retrieve data by joining multiple tables together, that's in the repository. The...

Generic Repository Pattern IEntity property case sensitivity

c#,asp.net-mvc,design-patterns,repository-pattern

If you're using a code first approach, Entity Framework will automatically pluralize your entity names when generating the tables, so lets add some context to your question first and remove all that abstraction, lets say we're creating a User repository, entity frameworks will automatically generate a Users table. public partial...

Repository/UnitOfWork Add throws Cannot insert the value NULL into column error

c#,.net,entity-framework,repository-pattern,n-tier-architecture

Per this question: Cannot insert the value NULL into column in ASP.NET MVC Entity Framework The answer came down to adding [DatabaseGenerated(DatabaseGeneratedOption.None)] to my Entity runs like a charm. Huge shout out to @JeffTreuting for pointing me in the right direction with the SQL Trace. I honestly hadn't even thought...

Using Iqueryable with Generic Repository doesn't find Records

c#,repository,repository-pattern,structuremap

The Find method does not expect a generic type and the where clause is returning an IEnumerable which you're attempting to cast as Employee. Replace the where clause with FirstOrDefault. e.g. _employeeRepository.Find() .FirstOrDefault(i => i.User_Name == employee.User_Name) ...

Does Repository pattern kills ORM?

orm,domain-driven-design,repository-pattern

I have been thinking for some time that if one were to remove the change-tracking from an ORM then developers would see far less value in them. Lazy-loading should never happen. An aggregate is always loaded in its entirety. If you find yourself requiring lazy-loading chances are that you are...

Domain Design crossing Aggregate Root Boundaries

c#,nhibernate,domain-driven-design,repository-pattern

I think the key here is that you want to change the thought process to entity to entity or value object relationships. In the way you are modeling your classes, you have a UserId as a property and are talking about it as if it was a relationship. I think...

ASP.NET Identity with Repository and Unit of Work

c#,entity-framework,repository-pattern,asp.net-identity,unit-of-work

Found some sort of solution, which looks generic enough, but I'm still not sure if it's really good and doesn't break Repository/UnitOfWork pattern principles. I added generic GetDbContext() method to my IUnitOfWork: public interface IUnitOfWork : IDisposable { void Save(); IRepository<TEntity> GetRepository<TEntity>() where TEntity : class; TContext GetDbContext<TContext>() where TContext...

Change DB in the runtime using Generic Repository and IoC

c#,repository-pattern,simple-injector

First of all, you will have a serious problem here, because to do this, you will have to know the password of each user, or make it plain somehow. I'm not sure if it can be done. If it can, the code below will give you a good starting point....

Having a repository dependent on another repository

c#,repository-pattern,solid-principles

Repository should have single responsibility - persist one kind of entity. E.g. employees. If you have to delete some associated records from other repository, it looks like business logic. E.g. When employee is fired we should remove his work log And usual place for business logic is a domain services....

Getting entity with referenced entities in EF

entity-framework,repository-pattern,unit-of-work

any .Include() calls should be added after the query is constructed, otherwise they are ignored. You should write public IQueryable<T> SearchFor(Expression<Func<T, bool>> predicate, string includePath = null) { var query = DbSet.Where(predicate); if (!string.IsNullOrEmpty(includePath)) { query = query.Include(includePath); } return query; } Your problem is also that you did DbSet.Include(includePath)...

When to expose an IEnumerable instead of an ICollection?

asp.net-mvc,entity-framework,ef-code-first,repository-pattern

But [with ICollection] I can add new order in Controller without using service or repository. You mean you can do this (assuming there's a viewmodel for adding an order to a user and a SaveChanges() somewhere): public class UserController { public ActionResult AddUserOrder(AddUserOrderModel addOrder) { User user = User.GetByEmail(addOrder.UserEmail);...

Map sql query results to domain model

c#,domain-driven-design,repository-pattern

You can use PropertyInfo (Like the following): foreach (PropertyInfo propInfo in theType.GetProperties()) { for (int i = 0; i < reader.FieldCount; i++) { if (reader.GetName(i).Trim().ToLower() == propInfo.Name.Trim().ToLower()) { object asObj = reader.GetValue(i); if (asObj is System.DBNull) propInfo.SetValue(thisRow, null, null); else propInfo.SetValue(thisRow, reader.GetValue(i), null); } } } The type would be...

EF Code First check for property in generic repository

entity-framework,asp.net-mvc-5,repository-pattern,code-first

I could not find a suitable solution to my problem. After more searching i ended with 3 solutions: Create extension methods. Create a custom IDbSet which can accept a filter expression. Add a discriminator to every model. I choosed solution(3) although, I don't like it much...

How to use the Repository Pattern to handle complex Reads(SELECTs)?

php,mysql,repository-pattern,laravel-5

(Sometimes, I believe the "Answer" to a question involves "lowering expectations".) I believe you are asking too much for a "Repository Pattern". There are many 3rd party software packages that attempt to isolate the user from MySQL. They generally have limitations. Often a limitation is in scaling -- they are...

What kind of error codes should a repository return to a RESTful Web API

c#,entity-framework,repository-pattern

There are two major options: Treat situations like NotFound as exceptional. Specify exception types that will be thrown by your repository in situations where the object you meant to delete wasn't there. If you choose this option, then you can have a very general exception-catching handler at the Web API...

How can I wrap multiple business transactions under another transaction?

c#,transactions,repository-pattern,service-layer

You need to make both methods share the same database connection and transaction. How you do that is your choice. Your code looks like an anti-pattern. You're supposed to use one ObjectContext per unit-of-work where the UOW scope should encompass everything you need to do. Often, the scope is an...

How to keep helper methods when using Repository pattern in Laravel 5?

laravel,repository-pattern,laravel-5,solid-principles

What you get from User::all() or basically every Eloquent query is a Illuminate\Database\Eloquent\Collection. The problem is that when you call toArray() on the collection it will convert all the items of the collection into an array too and you loose all the methods of your model. Instead you can call...

A specified Include path is not valid. The EntityType '*Propiedad' does not declare a navigation property with the name 'Nombre'

c#,asp.net-mvc,entity-framework,asp.net-mvc-4,repository-pattern

Include is made to eagerly load navigation properties, meaning any property that is, in fact, another related entity. Since Nombre is a string, you do not need to include it: it is part of the entity that is returned from the database call. If Nombre were of a class representing...

asp mvc - generic repository and unit of work - override repository method

c#,asp.net-mvc,repository-pattern,unit-of-work

I think I understand this better after some time, so figured I would close it. I didn't need to "override" anything, I just needed to add the additional work in my unit of work class (duh), and then call the insert. Thanks for the thought provoking responses.

Sharing promises between modules vs having multiple promises

javascript,node.js,promise,repository-pattern,q

I have a feeling that the way I use promises is not correct Yes, you use the deferred antipattern a lot. Promises do chain, which means that you simply can return values and even promises from your then callback, and the .then() call will yield a promise for those...

Repository pattern design for multiple DbSets [duplicate]

c#,entity-framework,entity-framework-6,repository-pattern,repository-design

Honestly, I would not bother abstracting Entity Framework behind a repository unless you have a very good reason. You will create more work, make it harder on you in the future, and I believe EF is already a good enough abstraction from the persistence logic. That being said, if you...