I have a class with a title in it. I have a property that returns that title adjusted a bit. If I do Linq to Sql queries off the adjusted title property I get the "not supported" exception. If I do the same thing the property does directly in the linq query it works. Any ideas on how I can make the property work in Linq to Sql?
Here is the property
public string SeoName
{
get { return Name.ToLower().Replace(" ", "").Replace("&", "and"); }
}
Here is the query that doesn't work (What I would like to be able to do).
var series = from s in videoRepo.GetShows()
where s.Topic.SeoName.Equals(topicSeoName)
select s;
Here is a query that does the same thing and works
var series = from s in videoRepo.GetShows()
where s.Topic.Name.ToLower().Replace(" ", "")
.Replace("&", "and").Equals(topicSeoName)
select s;
How can I structure the top property to work with the first linq query?
MY FINAL ANSWER
Added an expression that evaluated what I was looking for
public static Expression<Func<Show, bool>>
TopicSeoNameEquals(string name)
{
return t => t.Topic.Name.ToLower().
Replace(" ", "").Replace("&", "").Equals(name);
}
Then, I just called it a bit differently in the linq query
var test = Show.TopicSeoNameEquals(topicSeoName);
var series = from s in videoRepo.GetShows().Where(test)
select s;