If you've done any development with jQuery Mobile you've likely used the Listview Widget. It's a handy little component that makes rendering list data a breeze. Even better, it has a built in search filter that you can enable by simply decorating your list element with data-filter="true"
The default behavior of the Listview Widget's filter is to match on a single term. The moment you add an additional space into your search string, look out! But, if you need multi-term search behavior in your filter, it's easy to add.
Monday, February 24, 2014
Tuesday, February 4, 2014
Quick and Compliant Email Templates using Razor
Even in today's hyper connected world where you can Tweet someone's TV or Instagram your refrigerator, it seems like when it comes to business, Email is still king. If you need a simple, effective, and fast way to create a templated email in code, I suggest using Razor as your templating engine.
If you've done any MVC development since version 3, you've likely used the new Razor View Engine. Its concise and semantic, and it gets out of the way of your html. Best of all, it's not dependent on MVC, so you can re-purpose it in many different ways.
There are already a few existing projects that surround Razor templates. In this example I'm using the following project, but you can use whatever you prefer to get the job done:
https://github.com/volkovku/RazorTemplates
I like the RazorTemplates project because like Razor itself, the syntax in the RazorTemplates project is concise and semantic.
I like the RazorTemplates project because like Razor itself, the syntax in the RazorTemplates project is concise and semantic.
Monday, January 27, 2014
Generic Repositories Including Includes!
The real credit for this solution goes to Steve Moss. He posted this article last year:
http://www.appetere.com/Blogs/SteveM/May-2012/Passing-Include-statements-into-a-Repository
All that I've done is modified his work to fit in with the generic repository pattern that I often use.
http://www.viamacchina.com/2013/07/a-generic-repository-for-entity.html
One of the difficulties in using a repository to manage your data is that the repository itself can end up obscuring functionality from the underlying data provider. The pattern that I previously wrote about did just this. If you needed to Include relationships that were not originally established in your entity model, you had to create additional logic to retrieve that missing data.
As the Entity Framework has matured, the support for Including data from related entities has improved. Specifically, since EF 4.1, you can use strongly typed lambda's to specify relationships to eagerly load data. This, in combination with the existing string "Include", make working with entity relationships much more convenient.
To extend the original repository pattern to support dynamic includes, all that has to be done is to add an additional Select overload to the repository interface, and then make a quick change to the base class and the child classes that implement it.
1. Update the interface definition. The overloaded Select method that accepts an array of Expressions is the key.
http://www.appetere.com/Blogs/SteveM/May-2012/Passing-Include-statements-into-a-Repository
All that I've done is modified his work to fit in with the generic repository pattern that I often use.
http://www.viamacchina.com/2013/07/a-generic-repository-for-entity.html
One of the difficulties in using a repository to manage your data is that the repository itself can end up obscuring functionality from the underlying data provider. The pattern that I previously wrote about did just this. If you needed to Include relationships that were not originally established in your entity model, you had to create additional logic to retrieve that missing data.
As the Entity Framework has matured, the support for Including data from related entities has improved. Specifically, since EF 4.1, you can use strongly typed lambda's to specify relationships to eagerly load data. This, in combination with the existing string "Include", make working with entity relationships much more convenient.
To extend the original repository pattern to support dynamic includes, all that has to be done is to add an additional Select overload to the repository interface, and then make a quick change to the base class and the child classes that implement it.
1. Update the interface definition. The overloaded Select method that accepts an array of Expressions is the key.
public interface IRepository : IDisposable
{
void Insert<E>(E entity) where E : class;
void Update<E>(E entity) where E : class;
void Delete<E>(E entity) where E : class;
IQueryable<E> Select<E>() where E : class;
IQueryable<E> Select<E>(params Expression<Func<E, object>>[] includeExpressions) where E : class;
E Select<E>(object key) where E : class;
}
Thursday, October 24, 2013
Lights, Camera, Action Delegates!
I recently worked on a project that a number of other developers collaborated on. All of the contributors to the project are very smart people, and I was impressed by much of the work that they had done. But one thing caught my eye, and I want to write a post about it since there are folks out there that are not familiar with this technique.
The Func and Action delegates were introduced in .Net 3.5 and they have a variety of uses. One of the best uses that I have found for them is to separate procedural code from actual business logic. Specifically, I like to create methods that accept an action delegate to control database, Entity Framework, or Linq to Sql contexts, and WCF service operations.
The Func and Action delegates were introduced in .Net 3.5 and they have a variety of uses. One of the best uses that I have found for them is to separate procedural code from actual business logic. Specifically, I like to create methods that accept an action delegate to control database, Entity Framework, or Linq to Sql contexts, and WCF service operations.
In the project I was working on I repeatedly found classes in the data layer with code like this (in this example a connection object has already been created and passed into the class) :
IDbCommand dbCommand = connection.CreateCommand();
dbCommand.CommandText = "Command_Text";
try
{
if (dbCommand.Connection.State == ConnectionState.Closed)
dbCommand.Connection.Open();
dbCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
Log.DefaultLog.WriteVerbose(ex.Message + Environment.NewLine + ex.StackTrace);
throw ex;
}
finally
{
if (dbCommand != null && dbCommand.Connection != null && dbCommand.Connection.State == ConnectionState.Open)
dbCommand.Connection.Close();
}
Tuesday, August 27, 2013
Subscribe to:
Posts (Atom)
