Last active
August 29, 2015 14:18
-
-
Save dnasca/2cf61e8ca29c702ada29 to your computer and use it in GitHub Desktop.
Creating a Data layer - 2.) The Database Context - Inheriting from DbContext
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
| /* | |
| Entity framework expects a Context class. This class is used to communicate between the code and the dB. Since we built our model | |
| classes by convention, we won't need to do much in the way of configuration of our context. | |
| This is the pipeline to all queries, inserts, updates, deletes for any data operation is going to be passed through. | |
| *The next class we'll build will be the NoteRepository class to wrap the context in. | |
| */ | |
| using System; | |
| using System.Collections.Generic; | |
| using System.Data.Entity; | |
| using System.Linq; | |
| using System.Web; | |
| namespace Note.Data | |
| { | |
| public class NoteContext : DbContext | |
| { | |
| //constructor is required | |
| public NoteContext() | |
| : base("DefaultConnection") // connectionString | |
| { | |
| // TO DO: Implement migrations here | |
| } | |
| // setup properties on this context to represent the tables to be stored in the dB | |
| // Entity will infer by the structure of these classes on how to build our dB | |
| public DbSet<Topic> Topics { get; set; } | |
| public DbSet<Reply> Replies { get; set; } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment