I'm gettin an error pointing to in
in the foreach loop!? Has never happens before. What could be the reason for this? Have I missed something?
Error message:
An exception of type 'System.NotSupportedException' occurred in EntityFramework.SqlServer.dll but was not handled in user code
Additional information: Unable to create a constant value of type 'System.Object'. Only primitive types or enumeration types are supported in this context.
My code:
List<int> WeeksInProject = new List<int>();
var w = from x in db.Activities
where x.ProjectID.Equals(1)
select x;
foreach (var wNum in w)
{
WeeksInProject.Add(wNum.WeekNumber);
}
var w = from x in db.Activities
where x.ProjectID.Equals(1) select x;
should be:
var w = from x in db.Activities
where x.ProjectID == 1 select x;
If ProjectID
is int?
,
var w = from x in db.Activities where
x.ProjectID.HasValue &&
x.ProjectID.Value == 1 select x;
List<int> WeeksInProject = new List<int>();
var w = from x in db.Activities
where x.ProjectID != null && (int)x.ProjectID == 1
select x;
foreach (var wNum in w)
{
WeeksInProject.Add(wNum.WeekNumber);
}
Since the ProjectID is an int?
you have to check for nullity and then cast it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With