Parent_ObjectiveID
y identity
son int?
tipo de datos. En mi programa debería devolver un objeto, pero da un error: Sequence contains no elements
.Problemas con tipos anulables en una función LINQ
int? identity = null;
Objective currentObjective = (from p in cd.Objective
where p.Parent_ObjectiveID == identity
select p).Single();
Aunque, si reemplazo la variable de identidad por nulo. Funciona, pero no entiendo.
currentObjective = (from p in cd.Objective
where p.Parent_ObjectiveID == null
select p).Single();
¿Qué está pasando?
ACTUALIZACIÓN 1:
he hecho esto:
if (identity == null)
{
currentObjective = (from p in cd.Objective
where p.Parent_ObjectiveID == null
select p).Single();
}
else
{
currentObjective = (from p in cd.Objective
where p.Parent_ObjectiveID == identity
select p).Single();
}
Pero en realidad no me gusta.
¿Estás hablando de Linq-To-Sql o Linq-To-Objects? Acabo de probar esto con Linq-To-Objects, y funciona para mí. (.NET 4.0) – magnattic
@atticae Linq a SQL –
¿Por qué lo etiquetó con 'linq-to-objects' luego? ;) – magnattic