I am stuck here with Linq query... I am just trying to get my hands on MVC via this very simple blog application.. I am hving these three entities
Post, AuthorDetails, CommentsDetails, //* in future will be adding categories, tags
i want to search using the searchterm passed into the methods, which will then search for that searchString in Post.Title, Post.Body,AuthorDetails.FirstName,AuthorDetails.LastName,CommentsDetails.Comments and waht to return something which i can cast to List<> ...please have a look what i have got so far.
Code..
public List<Post> GetPostBySearchItem(string searchString)
{
List<Post> getAllPostsBySearchString = (from p in ePost.Posts
join a in ePost.AuthorDetails
on p.AuthorId equals a.Id
join c in ePost.CommentsDetails
on a.Id equals c.Id
where p.Title.Contains(searchString) || p.PostBody.Contains(searchString) || a.FirstName.Contains(searchString) || c.Comments.Contains(searchString)
select p).ToList();
return getAllPostsBySearchString;
2 question here 1) whether the join statements are correct in this code 2) and how can i return something like this select P for Posts, A for AuthoreDetails and c for CommentsDetails...