Skip to content

Instantly share code, notes, and snippets.

@cerkit
Created March 24, 2014 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cerkit/9748886 to your computer and use it in GitHub Desktop.
Save cerkit/9748886 to your computer and use it in GitHub Desktop.
This is the generic base repository class that handles data store operations with the Entity classes.
using Newtonsoft.Json;
using RecordKeeper.Portable.Models;
using System.IO;
using System.Security.Principal;
using System.Threading;
namespace RecordKeeper.Data.Repositories
{
public abstract class RepositoryBase<TEntity> where TEntity : EntityBase
{
protected readonly IIdentity Identity;
protected readonly string ConnectionString;
protected RepositoryBase()
{
ConnectionString = "Your Database Connection String Here";
Identity = Thread.CurrentPrincipal.Identity;
}
public static TEntity FromJson(string json)
{
TEntity entity;
JsonSerializer s = new JsonSerializer();
StringReader sr = new StringReader(json);
JsonTextReader r = new JsonTextReader(sr);
entity = s.Deserialize<TEntity>(r);
return entity;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment