One of the main problems in your current approach is that the repositories individually have the responsibility to create/update the entities they hold on the database - This means that if you have changes in one repository and update another repository (i.e. your
Create() call) both will be committed to the DB.
The usual way to structure this is having a unit of work (i.e. see here) that sits on top of all repositories that is responsible to commit changes to the DB, this structure also allows for transactions spanning multiple repositories.
I would say you should probably keep the responsibility of the repository to be saving and retrieving data for the entity. The "role" is a bit more on the "business logic" side and I would put that one layer up in a Service so you don't do any business logic responsibilities in the repository. For example you could call it CreateNewUserService and it would take the new users from the repository and then add the role. You would call that directly from the controller passing those arguments that you are applying directly now.
That way if your business logic changes so that you want to intialize the user as something else or not at all, you don't have to rip up the repository as it can keep it's responsibility of providing the user. This keeps the separation of concerns to be more clear as well and helps with maintenance and testability of both the repository and the service.
- LINQ-to-SQL repository pattern attempt that is working, but am concerned with seperation
- Linq sub query when using a repository pattern with EF code first
- Linq to SQL update not working using Repository pattern
- Compiled Linq with Generic Repository Design Pattern
- Linq Code with Distinct or GroupBy not working
- Distinct not working with LINQ to Objects
- Error: "The specified LINQ expression contains references to queries that are associated with different contexts"
- How are people unit testing code that uses Linq to SQL
- How to count the number of elements that match a condition with LINQ
- jqgrid with asp.net webmethod and json working with sorting, paging, searching and LINQ -- but needs dynamic operators
- Best practices for dealing with LINQ statements that result in empty sequences and the like?
- How to insert a record with LINQ and C# and return the Primary Key of that record
- linq how to select a parent with a child collection that contains one or many of an array (or list) of values
- How can I set properties on all items from a linq query with values from another object that is also pulled from a query?
- Distinct not working with LINQ
- VB.NET linq group by with anonymous types not working as expected
- C# Replace all elements of List<string> with the same pattern with LINQ
- Using LINQ to search a byte array for all subarrays that start/stop with certain byte
- Dealing with Queries in a Repository Pattern with multiple concrete implementations?
- Is there a good source that gives an overview of linq optimizations?
- LINQ Lambda query 'select' not working with oData
- How can I use linq to return integers in one array that do not match up with an integer property of another array?
- Is there a JS library that supports writing linq to sql queries with nodejs?
- Determine, that sequence contains other sequence, in same order, with using LINQ
- LINQ query with two joins that worked in EF 6 gives error in EF 7
- LINQ Source Code Available
- How can I switch that code to use LINQ
- How does this linq code that splits a sequence work?
- Linq with where clause in many-to-many EF Code First object
- C# Code Contracts -- How to ensure that a collection of items contains items with unique properties?
- LINQ returns arrays, not a collection of list object
- Error with two structurally incompatible initializations within a single LINQ
- Search by Letters using LINQ
- Linq Where Condtion For Different Types
- Apply dynamic where clause to joined table
- Better way of comparing two lists with LINQ?
- Linq to Entities : Left Join and filter
- Why LINQ Count() returning multiple rows instead one?
- Checking if a non-list variable satisfies a predicate expression
- c# linq GroupBy on the values of a List within a List
- Nested select with group by using linq
- join with multiple group by element and select extra columns
- Linq group by DateTime.Date and then group by another criterium
- Cant save '\r\n' tag from Enviroment.NewLine into database
- Query always returns all records
- Linq not equal to returning all values in wpf datagrid
- Linq output changes
- How to add a where clause to this Entity Framework Linq statement
- Sitecore search: Get results term by term
- LINQ to SQL Search Query results to listbox, help transferring selecteditems to a new listbox