Isn’t symmetry nice? I always have some OCD when it comes to diagrams. So, it’s not surprise when you see this screenshot of the Linq2Sql Context
Along with this, now we can go ahead and create Athena.DAL which contains the Linq2Sql context.
The solution isn’t that far long, so I won’t put up any code yet.
From this fantastic post on implementing the Repository pattern using Linq2SQL, we quickly put together some code that resembles the following
The Repository Interface
namespace Athena.DAL
{
/// <summary>
/// Repository Contract
/// </summary>
public interface IRepository<TRow, TEntity>
where TRow : class
{
#region Find
IList<TEntity> Find(Expression<Func<TRow, bool>> exp);
TEntity FindSingle(Expression<Func<TRow, bool>> exp);
#endregion
#region Save
void Save(TEntity entity);
#endregion
#region Delete
void Delete(TEntity entity);
#endregion
}
}
Our Entry Model, which will describe an Entry fully
namespace Athena.DAL
{
/// <summary>
/// Entry Model
/// </summary>
public class EntryModel
{
public Entry Entry { get; set; }
public List<Tag> Tags { get; set; }
public List<Category> Categories { get; set; }
}
}
and now for our not yet implemented EntryRepository
namespace Athena.DAL
{
/// <summary>
/// Entry Repository
/// </summary>
public class EntryRepository : IRepository<Entry, EntryModel>
{
#region Find
/// <summary>
/// Find
/// </summary>
/// <param name="exp"></param>
/// <returns></returns>
public IList<EntryModel> Find(System.Linq.Expressions.Expression<Func<Entry, bool>> exp)
{
throw new NotImplementedException();
}
/// <summary>
/// Find Single
/// </summary>
/// <param name="exp"></param>
/// <returns></returns>
public EntryModel FindSingle(System.Linq.Expressions.Expression<Func<Entry, bool>> exp)
{
throw new NotImplementedException();
}
#endregion
#region Save
/// <summary>
/// Save
/// </summary>
/// <param name="entity"></param>
public void Save(EntryModel entityModel)
{
throw new NotImplementedException();
}
#endregion
#region Delete
/// <summary>
/// Delete
/// </summary>
/// <param name="entity"></param>
public void Delete(EntryModel entityModel)
{
throw new NotImplementedException();
}
#endregion
}
}
88900210-1026-48dc-8bb3-13181c890c4a|0|.0