views:

51

answers:

1

I need to strip the following chars from my records using LINQ to SQL query

"\";:'.,=+!@#$%^&*(_)~{}[]\\|<>? aeiouAEIOU"

I can do it with my linq query here

from p in customers 
select new {customer_name = String.Concat(p.First_name.Replace("A","@"),p.Last_name.Replace("A","@")), address =  p.Address.Replace("A","@") }

but I know there must be a better way to do this! I tried a method in c# to strip the chars but since this is linq to sql it doesn't work. The error says "that has no supported translation to SQL"

I need some ideas and code samples on how to write this routine in c#. Or possibly write a sql function to do this and example of how to do that.

+1  A: 

However you choose to update the records, you can use the Regex.Replace() method to replace unwanted characters in a string.

For example:

using System.Text.RegularExpressions;

// ...

string unwanted = @"["";:'.,=+!@#$%^&*(_)~{}\[\]\\|<>? aeiouAEIOU]";

string subject = "The quick brown fox jumped over the lazy dog.";

string result = Regex.Replace(subject, unwanted, string.Empty);
// Thqckbrwnfxjmpdvrthlzydg

Read more about Regular Expressions and the .NET implementation.

Bauer
linq error says "no supported translation to SQL" - any other ideas?
kiev
Get the customer objects, update them, and THEN save the updated values back to the database, instead of trying to update them as part of the select?
Joel Mueller