Skip to main content
Tweeted twitter.com/#!/StackProgrammer/status/293660125384810496
spelling, formatting, personal stuff cleanup
Source Link
gnat
  • 20.9k
  • 29
  • 115
  • 295

Are we using the repository pattern right?

weWe are using a bunch of separate classes suffixed with -repository-repository to retrieve the data from the database; for each table its own repository. We

We have for instance a customerrepositorycustomerrepository class which has all kind of methods to retrieve customers, and a vacancyrepositoryvacancyrepository which has all kind of methods to retrieve vacancies.

now iI have two questions about this way of doing things:

one is: how about getting data which spans multiple tables. For instance i have a screen which shows all customers who have not yet created a vacancy. Can a customerrepository use methods from the vacancyrespository, or do both repositories return results and is there a class higher in the hierarchie (lets name it a dataservice) which gets the results from both repositories and combine them into 1 result?

second is: how much logic can such a repository handle? I think it's ok to implement the 'where active == true' in a repository to retrieve only active records, or should even that simple logic be handled by a class higher in the hierarchie (lets name it a dataservice)?

  1. How about getting data which spans multiple tables? For instance I have a screen which shows all customers who have not yet created a vacancy. Can a customerrepository use methods from the vacancyrespository, or do both repositories return results and is there a class higher in the hierarchy (let's name it a dataservice) which gets the results from both repositories and combine them into 1 result?

  2. how much logic can such a repository handle?
    I think it's OK to implement the 'where active == true' in a repository to retrieve only active records, or should even that simple logic be handled by a class higher in the hierarchy (let's name it a dataservice)?

The example iI was running into now is this one: We

We have a questions list, which contains one or more questions. 
The question can have a result, which is hold in a separate table. 
So when yoiuyou want to retrieve the total result of the questions list, you have to combine data from the questionlistquestionlist table, the question table and the questionstatusquestionstatus table. Right

Right now we have 3 different repositories for thosethese tables.

If iI would ask the questionlistrepositoryquestionlistrepository what it's the total result for list number 12, it would have to get data from two other repositories and hence have some logic in it, is that allowed? Or

Or is there a questionlistdataservicequestionlistdataservice which knows which repositories to use?

One more thing: our repositories can result an IQueryableIQueryable so a calling service can easily combine the results, but how about thenwhen this isn't the case, iI don't think it's a good idea to retriveretrieve all the content of all three tables from the database....

Lost of questions in one i know.... if you have only a partial answer that's ok too :-)

Are we using the repository right?

we are using bunch of separate classes suffixed with -repository to retrieve the data from the database; for each table its own repository. We have for instance a customerrepository class which has all kind of methods to retrieve customers, and a vacancyrepository which has all kind of methods to retrieve vacancies.

now i have two questions about this way of doing things:

one is: how about getting data which spans multiple tables. For instance i have a screen which shows all customers who have not yet created a vacancy. Can a customerrepository use methods from the vacancyrespository, or do both repositories return results and is there a class higher in the hierarchie (lets name it a dataservice) which gets the results from both repositories and combine them into 1 result?

second is: how much logic can such a repository handle? I think it's ok to implement the 'where active == true' in a repository to retrieve only active records, or should even that simple logic be handled by a class higher in the hierarchie (lets name it a dataservice)?

The example i was running into now is this one: We have a questions list, which contains one or more questions. The question can have a result, which is hold in a separate table. So when yoiu want to retrieve the total result of the questions list, you have to combine data from the questionlist table, the question table and the questionstatus table. Right now we have 3 different repositories for those tables.

If i would ask the questionlistrepository what it's the total result for list number 12, it would have to get data from two other repositories and hence have some logic in it, is that allowed? Or is there a questionlistdataservice which knows which repositories to use?

One more thing: our repositories can result an IQueryable so a calling service can easily combine the results, but how about then this isn't the case, i don't think it's a good idea to retrive all the content of all three tables from the database....

Lost of questions in one i know.... if you have only a partial answer that's ok too :-)

Are we using the repository pattern right?

We are using a bunch of separate classes suffixed with -repository to retrieve the data from the database; for each table its own repository.

We have for instance a customerrepository class which has all kind of methods to retrieve customers, and a vacancyrepository which has all kind of methods to retrieve vacancies.

I have two questions about this way of doing things:

  1. How about getting data which spans multiple tables? For instance I have a screen which shows all customers who have not yet created a vacancy. Can a customerrepository use methods from the vacancyrespository, or do both repositories return results and is there a class higher in the hierarchy (let's name it a dataservice) which gets the results from both repositories and combine them into 1 result?

  2. how much logic can such a repository handle?
    I think it's OK to implement the 'where active == true' in a repository to retrieve only active records, or should even that simple logic be handled by a class higher in the hierarchy (let's name it a dataservice)?

The example I was running into now is this one:

We have a questions list, which contains one or more questions. 
The question can have a result, which is hold in a separate table. 
So when you want to retrieve the total result of the questions list, you have to combine data from the questionlist table, the question table and the questionstatus table.

Right now we have 3 different repositories for these tables.

If I would ask the questionlistrepository what it's the total result for list number 12, it would have to get data from two other repositories and hence have some logic in it, is that allowed?

Or is there a questionlistdataservice which knows which repositories to use?

One more thing: our repositories can result an IQueryable so a calling service can easily combine the results, but how about when this isn't the case, I don't think it's a good idea to retrieve all the content of all three tables from the database.

Source Link
Michel
  • 971
  • 1
  • 7
  • 17

Are we using the repository right?

we are using bunch of separate classes suffixed with -repository to retrieve the data from the database; for each table its own repository. We have for instance a customerrepository class which has all kind of methods to retrieve customers, and a vacancyrepository which has all kind of methods to retrieve vacancies.

now i have two questions about this way of doing things:

one is: how about getting data which spans multiple tables. For instance i have a screen which shows all customers who have not yet created a vacancy. Can a customerrepository use methods from the vacancyrespository, or do both repositories return results and is there a class higher in the hierarchie (lets name it a dataservice) which gets the results from both repositories and combine them into 1 result?

second is: how much logic can such a repository handle? I think it's ok to implement the 'where active == true' in a repository to retrieve only active records, or should even that simple logic be handled by a class higher in the hierarchie (lets name it a dataservice)?

The example i was running into now is this one: We have a questions list, which contains one or more questions. The question can have a result, which is hold in a separate table. So when yoiu want to retrieve the total result of the questions list, you have to combine data from the questionlist table, the question table and the questionstatus table. Right now we have 3 different repositories for those tables.

If i would ask the questionlistrepository what it's the total result for list number 12, it would have to get data from two other repositories and hence have some logic in it, is that allowed? Or is there a questionlistdataservice which knows which repositories to use?

One more thing: our repositories can result an IQueryable so a calling service can easily combine the results, but how about then this isn't the case, i don't think it's a good idea to retrive all the content of all three tables from the database....

Lost of questions in one i know.... if you have only a partial answer that's ok too :-)