Book Image

SignalR Blueprints

By : Einar Ingerbrigsten
Book Image

SignalR Blueprints

By: Einar Ingerbrigsten

Overview of this book

Table of Contents (18 chapters)
SignalR Blueprints
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
9
Debugging or Troubleshooting
Index

Putting in place the Data Access Layer


Let's create a new folder at the root of the project called Data Access Layer (DAL). As we only have one domain-specific model, we will need only one context that enables us to have access to the database for this type. Add a class to the DAL folder called ArticleContext.cs.

Let's start by adding the following code into the file:

using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using Chapter3.Models.News;

namespace Chapter3.DAL
{
    public class ArticleContext : DbContext
    {
        public ArticleContext() : base("DefaultConnection") { }
        public DbSet<Article> Articles { get; set; }

        public IEnumerable<Article> GetArticles()
        {
            return Articles.OrderByDescending(a => a.PublishedDate);
        }
    }
}

As you can see, we expose a public Articles property that Entity Framework will ensure gets set up. Secondly, we expose a public way of getting all articles...