Pages

Thursday, June 28, 2012

No ELMAH, forget about it!

If you haven't heard of ELMAH you need to check out the following links pronto!

ELMAH - Home
Scott Hanselman on ELMAH

I highly recommend using ELMAH whenever you can when developing custom applications. There are very few things that you can "bolt-on" to your application that will provide so much functionality with so little effort.

But what happens when you can't use ELMAH? If for some reason you can't use ELMAH in your application (like, for say... you work with an old school architect who just doesn't get it, and doesn't want to try to get it) then what do you do? What you do is forget about it, and write your own!

Wednesday, June 27, 2012

Using Pete Montgomery’s Universal Predicate Builder with a generic repository

I gave a presentation the other day that included a generic repository class that I created and use in many of my Entity Framework projects. I like the implementation because it is flexible and easy to extend. I've created a blog post about the RepositoryBase class here:

A Generic Repository for the Entity Framework

After the presentation I was asked how I utilized the repository's Select methods. In this case, the Select Method is overridden a few times to match the select pattern used by ASP.Net ObjectDataSources. Essentially, I can create a repository class that will map 1 to 1 to an ObjectDataSource to enable paging and sorting.

Wednesday, June 13, 2012

A Generic Repository for the Entity Framework

Note: In this post I am going to be demonstrating techniques that depend on the Entity Framework 4.1 or higher.

Recently I’ve been using a simple Repository oriented architecture for my Entity Framework projects. Coupled with the new DbContext class and the entity code generation items added in the Entity Framework 4.1 release you can quickly scaffold up a data layer and business layer for your application.

To start, let’s define an interface for our repository:

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;

    E Select<E>(object key) where E : class;

    int SaveChanges();

    int SaveChanges(bool validateEntities);
}

Wednesday, November 30, 2011

Automate your test data with Red Gate SQL Data Generator

Just about every developer out there has encountered a scenario where they need to load test the application they are creating, but simply cannot come up with enough load to make it happen. I'm not going to go down the rabbit hole that is load testing an application in this post, but I do want to talk about one component of load testing, which is working with a lot of data. I seem to always run into the situation where I'm developing an application for a client, and when it comes time to test the application in a real world scenario and need real world data, the only viable solution is to back up data from a production server and massage it to "fit" into my applications database. Bad idea. Yes, there are times when this is unavoidable, but in general, do you really want to make multiple copies of sensitive data? Also, in most cases I cannot just copy and paste the data into my database. In the past I've created a number of data migration utilities, data population scripts, and used a number of tools just to populate my application with data that I can use to test it. All of this takes time, and effort.

In contrast, there is Red Gate's SQL Data Generator. The SQL Data Generator is aptly named, because that is what it does, it generates data. And good data in fact. I downloaded the product trial recently when trying to hand jam a data population script for over 1,000,000 rows of data in multiple keyed tables. Needless to say, I became a little frustrated and started looking for alternatives. I downloaded the tool to my machine, installed it, and generated 1,000,000 rows of data for all of my tables in under 10 minutes. Nice. In addition to simply generating data, the SQL Data Generator is smart enough to create records that enforce referential integrity, that match data types, and in some cases, even provide data reflective of the column name. In one case, I have a column that is of type VARCHAR named STATE. The data created included all 50 US State names.


Wednesday, October 19, 2011

SSIS Attunity Connectors

Recently I had to create an SSIS package that transferred a huge amount of data between an Oracle database and a MS SQL Server database. I began creating an SSIS package that used an existing linked server connection that the client had already been using to perform similar data transfers. To my dismay, the performance of the linked server was dismal. Instead of using the linked server I decided to go with the OOTB OLE DB data source available in SSIS. This increased my performance dramatically. However, when I spoke to a colleague at TCSC, he recommended that I try the Microsoft Connectors for Oracle by Attunity. I had never heard of these connectors, but I was intrigued, so I downloaded them and ran some performance test.

The following tests results we recorded while debugging through Visual Studio, so real numbers will be better than what I have recorded, but the results do represent without a doubt the performance differences between the different connections.


Attunity
OLE DB
Linked Server
3000 rows
2 seconds

6 seconds

10 seconds
10,000 rows
3 seconds

10 seconds

20 seconds
100,000 rows
19 seconds

1 minute 28 seconds

3 minutes 2 seconds
500,000 rows
1 minute 23 seconds

7 minutes 35 seconds

16 minutes 18 seconds
1,000,000 rows
2 minutes 38 seconds

16 minutes 37 seconds

30 minutes 28 seconds