Created
April 11, 2015 09:10
-
-
Save dnasca/ae597dedfa8b92c3d333 to your computer and use it in GitHub Desktop.
Creating a Data layer - 3a.) Repository - Building an interface that will provide data access to the dB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| We'll use an interface because there are going to be places in the future when we want to be able to | |
| write unit tests. For example, to test against things like controllers. The controller will need a repository to do their data access. | |
| This allows us to split the methods that need to be implemented into a testing and live environment without having to re-write code. | |
| The interface will provide individual methods that have the data operations we will need. | |
| We will use the return type of IQueryable to return Topic objects. This is to allow users to page, sort, group, and filter. | |
| If we did not want/need to do this, we could use IEnumerable instead. This is important because any operations that are requested | |
| will be part of the dB execution-- rather than having to pull out all Topics and then only needing a certain few to pass back to the view. | |
| */ | |
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Text; | |
| using System.Threading.Tasks; | |
| namespace Note.Data | |
| { | |
| public interface INoteRepository | |
| { | |
| IQueryable<Topic> GetTopics(); | |
| IQueryable<Topic> GetTopicsIncludingReplies(); | |
| IQueryable<Reply> GetRepliesByTopic(int topicId); | |
| bool Save(); | |
| bool AddTopic(Topic newTopic); | |
| bool AddReply(Reply newReply); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment