I have the following code. but it causes exception.
using (var context = new blogEntities())
{
var listOfComments = context.Comments
.OrderByDescending(c => c.CreateDate)
.Where(c => c.CreateDate > fromDate)
.Select(c => new NewsFeedData()
{
ArticleID = c.ArticleID,
CommentID = c.CommentID,
Text = c.CommentText,
Author = c.Author,
CreateDate = c.CreateDate,
Type = 'C'
}).ToList();
}
Than I tried enum but there is some problems. What is the best way to achieve what I want?
I want to assign some constant to Type
One simple approach is to fetch all the values from the database into an anonymous type, then use
AsEnumerableto switch into LINQ to Objects before the final projection: