I am trying to sort different field. i.e. blogID, date, author
I found order by method but dont know how to pass the value in the method… help please
public List<blog> BlogFetch(string key)
{
List<blog> blogRes = new List<blog>();
using (var be = new BlogEntities())
{
blog res = new blog();
foreach (var User in be.blogs.OrderBy(<what goes here?>))
{
res = User;
blogRes.Add(res);
}
}
return blogRes;
}
It’s a Lambda expression which is used heavily in LINQ. Here’s a good “cheatsheet” on getting started with LINQ syntax.
As an aside if you want to load a List of items when using EF you can just call
ToList().