Perform ASP.NET Postback using JQuery
Came across a situation where I needed to disable the ASP.NET button using JQuery when the user clicks on the button, this is so we stop the user from clicking the button twice while the page is doing a postback. Firstly, add the following JQuery/Javascript code: <script> function autoSubmit() { <%= ClientScript.GetPostBackEventReference(btnSaveChanges, "") %>; } [...]
Some useful Extension Methods
Back to basics… A couple of useful Extension methods if you are checking if a string is a valid integer or decimal. public static bool IsInteger(this string value) { if (String.IsNullOrEmpty(value)) return false; Int32 tmpNo; return Int32.TryParse(value, out tmpNo); } public static bool IsDecimal(this string value) { if (String.IsNullOrEmpty(value)) return false; Decimal tmpNo; return Decimal.TryParse(value, [...]
Finding StoreGeneratedPattern value in EdmProperty in T4 Template
If you need to find out if a primary key in your conceptual model which is using the Identity value from the property StoreGeneratedPattern, you can use the following code: (NOTE: This is used within a T4 template) string inputFile = @"..\EntitiesModel.edmx"; EdmItemCollection ItemCollection = loader.CreateEdmItemCollection(inputFile); string annotationNamespace = "http://schemas.microsoft.com/ado/2009/02/edm/annotation"; foreach (EntityType entity in ItemCollection.GetItems<EntityType>().OrderBy(e [...]
You receive a “The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect” exception when using NVarchar parameters with Sqlclient
The problem I got the following random error: You receive a “The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect” exception when using NVarchar parameters with Sqlclient The Solution Its a known bug with the .Net SqlClient Data Provider. If you have a field in the database of type nvarchar(max) [...]
Open XML – OLE Automation Date Issues
If you are exporting a date from C# to Excel using 2007, you probably will use the following: Math.Round(DateTime.Now.ToOADate(), 12).ToString() This exports the date as a OLE Automation date recognized by Excel 2007. How ever, in Excel 2010 this was causing issues, every time I exported to Excel 2010, it said that it has to [...]
EF Strongly Typed ObjectQuery.Include
The problem that I faced was having to put up with “hard coded” strings in the ObjectQuery.Include function to load related objects through POCO objects in the Entity Framework. This faced challenges when I renamed columns in the Model which caused a run-time error when recompiling and re-starting the application. Thanks to David Kiff, we [...]
Fixing the EF Tracing and Caching Provider Wrapper Issue
If you have been using the Tracing and Caching Provider Wrappers for the ADO.NET Entity Framework 4.0, you might of come across this error message when creating POCO objects, adding them to a Data Context and commiting them to the database using the Caching Wrapper: [NotImplementedException: The method or operation is not implemented.] EFCachingProvider.EFCachingDataReaderCacheWriter.GetName(Int32 ordinal) [...]
Random number of items from a Generic List extension method
Here is a code snippet for returning N number of items from a generic list using a extension method. This requires .NET 3.5. public static class Extensions { /// <summary> /// method for returning N number of random items from a generic list [...]
Could not load file or assembly ‘NameOfAssemblyGoesHere’
Encounted the following error: Could not load file or assembly ‘NameOfAssemblyGoesHere’ or one of its dependencies. An attempt was made to load a program with an incorrect format. The problem happened when deploying a web application to a 64bit server where all the required DLL’s where marked as running only on a 32bit system. You [...]
Change username in ASP.NET Membership Provider
Found a great article here about the process of changing the username with the ASP.NET Membership Provider. Here is a summary of the process that I found best useful which is one of the comments: 1. Make sure New UserName is Unique 2. Update the aspnet_Users table directly 3. Execute to following code to change [...]


