c# - Constant in EF causes exception -
i have following code. 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 tried enum there problems. best way achieve want? want assign constant type
one simple approach fetch values database anonymous type, use asenumerable
switch linq objects before final projection:
using (var context = new blogentities()) { var listofcomments = context.comments .orderbydescending(c => c.createdate) .where(c => c.createdate > fromdate) .select(c => new { c.articleid, c.commentid, c.commenttext, c.author, c.createdate }) .asenumerable() // switch linq objects .select(c => new newsfeeddata { articleid = c.articleid, commentid = c.commentid, text = c.commenttext, author = c.author, createdate = c.createdate, type = 'c' }).tolist(); }
Comments
Post a Comment