ASP.NET MVC2 Linq Where Clause using StartsWith

寵の児 提交于 2019-12-02 09:27:45

Ok after our long comments below, why don't you just chain the linq statements like below?

if (collection["Filter"] == "2") { 
   presentations = presentations.Where(x => x.Person.FirstName.StartsWith("A")).
       OrderBy(x => x.Person.FirstName);
}

Since the Where and the OrderBy are deferred until you actually do something with the query like a ToList(), try doing:

var orderedData = presentations.ToList();

Inspect it, it should be in the correct order as I can't see anything wrong with your linq other than the code you posted never actually is executed until you do a Select or ToList or something with it.

I have managed to resolve the problem. If you look at the query the line

LEFT OUTER JOIN [Speakers] AS t1 ON ([t1].[Id] = [t0].[Id])

should read

LEFT OUTER JOIN [Speakers] AS t1 ON ([t1].[Id] = [t0].[SpeakerId])

Not quite sure why this is happening though, can anyone see how to correct this problem?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!