I am getting the following exception:
The null value cannot be assigned to a member with type S开发者_Go百科ystem.Int32 which is a non- nullable value type.
Below is my LINQ Statement where QuestionId is the primary key in my table:
var questionViewsData =
from questionViews in objDc.SC_QuestionsViews
join questions in objDc.SC_Questions
on questionViews.QuestionId equals questions.QuestionId into qs
from questions in qs.DefaultIfEmpty()
where questionViews.CreatedDate.Date == new DateTime(2010, 4,27)
select new
{
Selected =(questions == null ?-1:questions.QuestionId),
QuestioinTitle = questions.Title,
VotesCount = questions.VotesCount
};
Change the line
where questionViews.CreatedDate.Date == new DateTime(2010, 4,27)
to
where questionViews.CreatedDate == new DateTime(2010, 4, 27)
as a test you could run
where questionViews.CreatedDate > new DateTime(2010, 4, 26)
N.B. If I include .Date in a LinqPad c# statement I receive the following error message and removing .Date allows the statement to run.
System.Nullable<System.DateTime>' does not contain a definition for 'Date' and no
extension method 'Date' accepting a first argument of type
'System.Nullable<System.DateTime>' could be found
For starters, try running it with this:
select new
{
Selected = questions.QuestionId,
QuestioinTitle = questions.Title,
VotesCount = questions.VotesCount
};
What do you get?
精彩评论