0

Some useful Extension Methods

Posted by Tim on September 6, 2011 in .NET Framework, C#

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, [...]

Tags: , ,

 
0

OrderBy making null records come last Entity Framework and Linq

Posted by Tim on July 28, 2011 in .NET Framework, C#

Ever want to sort your result set but make sure the records with a null sorting column appear last? See the example below var results = (from x in EntityObjectContext.MyTable               select x               into grp               [...]

Tags: , ,

 
0

Finding StoreGeneratedPattern value in EdmProperty in T4 Template

Posted by Tim on May 11, 2011 in .NET Framework, C#, SQL Server

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 [...]

Tags: , ,

 
1

Disabling Request Validation with ASP.NET MVC

Posted by Tim on February 1, 2011 in C#, MVC

Sometimes when dealing with POSTS and form data, you need to disable Request Validation to allow HTML/scripting data into your methods.   Traditionally with Web Forms you use <%@ Page ValidateRequest=”false” %> which turns off Request Validation, just be aware that this doesn’t work with ASP.NET MVC. You apply the [ValidateInput] attribute to the controller action [...]

Tags:

 
1

Open XML – OLE Automation Date Issues

Posted by Tim on July 26, 2010 in .NET Framework, C#

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 [...]

Tags: , , ,

 
0

EF Strongly Typed ObjectQuery.Include

Posted by Tim on July 13, 2010 in .NET Framework, C#

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 [...]

Tags: ,

 
0

Fixing the EF Tracing and Caching Provider Wrapper Issue

Posted by Tim on July 9, 2010 in .NET Framework, C#

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) [...]

Tags: , ,

 
0

Random number of items from a Generic List extension method

Posted by Tim on June 13, 2010 in .NET Framework, C#

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     [...]

Tags: ,

 
1

The custom tool ‘MSLinqToSQLGenerator’ failed. Unspecified error

Posted by Tim on January 18, 2010 in .NET Framework, C#

I kept getting this error “The custom tool ‘MSLinqToSQLGenerator’ failed.  Unspecified error.   For me, this was caused when I was using partial classes and had several using statements at the top of the file: using System.Data.Linq; using System.Data.Linq.Mapping; using System.Data; using System.Collections.Generic; using System.Reflection; using System.Linq; using System.Linq.Expressions; using System.ComponentModel; using System; {namespace} {code} To [...]

Tags: , ,

 
0

Interview Questions Part 1

Posted by Tim on May 7, 2009 in .NET Framework, C#

Over the past month, I have been interviewed by several companies and I thought I would share some of my experiences.   Here are some of the questions I was asked (Technical): What is the difference between a reference type and a value type? What is the difference between a stack and a heap? What is [...]

Tags:

Copyright © 2008-2012 Codelab Blog All rights reserved.
Desk Mess Mirrored version 1.9.1 theme from BuyNowShop.com.