This is my code:
public DateTime GibSomeStartDate(IEnumerable<int> partnerNumbers, DateTime startTime)
{
var contractsStartDate = from contract in this.databaseContext.Contract
where partnerNumbers.Contains(contract.Pnr)
&& contract.SomeDateTime >= startTime
select contract.SomeDateTime;
}
if I call contractsStartDate.Min()
an Exception occurs:
Unable to create a null constant value of type 'System.Collections.Generic.IEnumerable`1'. Only entity types, enumeration types or primitive types are supported in this context.
What is wrong with my Query?
the contractsStartDate
is of type
System.Data.Entity.Infrastructure.DbQuery
EF 5.0
databaseContext
is child of System.Data.Entity.DbContext
I know this error. Just Make sure partnerNumbers
is not null. You're passing a null value for this parameter, but Linq-to-entities can't translate that value to anything meaningful.
if (partnerNumbers == null)
{
throw new ArgumentNullException("partnerNumbers");
}
An additional bonus advice:
If SomeDateTime
is not nullable
and there are no entries in your enumeration, then you'll get an exception on calling Min()
. Casting SomeDateTime
to the nullable
type in your query will work, then you get null when there are no entries.
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