I've got a C# string extension that really makes life easy, but I am getting the exception:
Method 'System.String ToUrlString(System.String)' has no supported translation to SQL.
I've seen this as a common problem and some people have found ways around fixing this for their method, but I'm not sure it's possible for mine. It's just a simple short cut and I've tried using it with a Regular Expression as well, and the same exception comes up.
public static string ToUrlString(this String val)
{
return val.Trim().ToLower().Replace(" ", "-").Replace(":", string.Empty);
}
Are there any additional decorators or ways I can adapt this code so that it can support SQL? I'm calling this on the where clause in my LINQ expressions. .ToTagString()
is not the exact same method as .ToUrlString()
but it's very similar.
EDIT: Per a suggestion below, here is something else I tried, but I am still getting the same error.
public IEnumerable<Post> GetPostsByTag(string tagName)
{
var query = from p in db.Posts
join pt in db.PostTags on p.PostID equals pt.PostID
where pt.Tag.TagName.ToTagString().Equals( tagName.ToTagString() )
orderby p.PostDate descending
select p;
var result = query.AsEnumerable();
return from r in result
select r;
}