If you try to use an extension method within LINQ to SQL you will run across this error:

This is exactly what happened to me. Let me take you through the steps of what I did and how I resolved it.
Say you have the below mentioned LINQ query.

You want to print out all the Customer names, but the all names in the database has different casing. A problem we developers usually have. So what you want to do is to display it in proper case. We would want to re-use this functionality in other places to. So the first thing that comes to mind is to create an extension method. Something that allows us to say String.ToTitleCase() as shown below.

So let us get to work. I added a new class file to my solution called extensions.cs with the following code:

This method will now allow me to use this with any string. See below example:

Now let’s use this new functionality within our LINQ query:

When we run our application now we get the following error:

That doesn’t seem to work. The reason for this now working is because LINQ to SQL doesn’t know how to translate the method “ToTitleCase()” into SQL code. It sees it as part of the LINQ expression. To get around this we need to create a partial method on our Customers data entity. All our LINQ to SQL entities consists out of partial classes. So we can implement another partial class on our existing classes to extend our functionality. There is different ways of implementing these classes by making use of different events in these classes, but I will just focus on a simple solution for now. So what you need to do is to add another class file to your project. We are going to extend the functionality of your existing LINQ to SQL entities. We don’t want our changes to be overwritten when we regenerate our data context. I added a new class file called Northwind_Extend.cs. I want to create a partial class of the Customer class. So i am going to create it exactly as it is within my data context using exactly the same interfaces:

What I am going to do now is to create a new property for CompanyName called CompanyNameProper. The reason why I have done this is because I don’t want to update my DB with the data formatted proper case. So this is what I have done next:

We also need to change our LINQ query to make use of the new property:

So when we run our application now, it works as it should!
