score:4
Accepted answer
max is looking to return an int because that's the type of p.level, but forced to return a null (because there are no items in the query). if you cast p.level to a nullable int, your query should work.
var nextlevel = (from p in cd.objective
where p.parent_objectiveid == null
select (int?)p.level).max();
Source: stackoverflow.com
Related Query
- How can I combine this code into one or two LINQ queries?
- How can I further simplify this piece of LINQ code
- How can i fix this error? c# asp linq
- How can I fix this LINQ so that it treats a pairs of vals as a distinct value?
- How can i optimize this linq function for calculating sum of "OrePreviste"?
- This LINQ statement crashes if one of the Properties is NULL. How can I fix this?
- How can I run this function inside LINQ query
- How can I fix this LINQ function?
- How can I refactor this code for LINQ filtering?
- How can I simplify this LINQ code
- How can i convert this code snippet into LINQ format?
- How can I fix the performance issue of this linq query?
- C# LINQ threw this error. how can I fix it?
- This function can only be invoked from LINQ to Entities. How can I solve this?
- How can i fix this method using Linq so that the test (which should already work because the result is correct) works?
- Unit test error : This function can only be invoked from LINQ to Entities
- How can I convert this SQL Query into LINQ (OVER (PARTITION BY Date))
- How do I write this in Ruby/Python? Or, can you translate my LINQ to Ruby/Python?
- How can I use LINQ to project this parent and children object model into a flat, single object?
- How can I call a local function inside a LINQ query?
- linq exception : This function can only be invoked from LINQ to Entities
- How can I switch that code to use LINQ
- How does this linq code that splits a sequence work?
- How can I GroupBy this LINQ query?
- How can I add OrderBy to this LINQ statement?
- How can I write the following code more elegantly using LINQ query syntax?
- How can I code an outer join using LINQ and EF6?
- How can I transform this linq expression?
- How can I get the highest number in this Linq result?
- DbFunctions.DiffDays() results in: This function can only be invoked from LINQ to Entities
More Query from same tag
- How to get the shortest country name from an array in C#
- Mock.Of<foo> Setting return for Method Calls With Parameters
- LINQ OrderBy on inner object's property
- how to remove a character at the end of a string in linq c#
- Can I generate a linq expression dynamically in C#?
- C# Linq equivalent for SQL script not responding
- Get distinct list of choices from a multiple choice field's data?
- LINQ Select Distinct While Evaluating Multiple Rows
- Linq output as an Interface?
- Is there a better way of writing this Linq Query
- Linq: How to get second last
- Expression for Linq between 2 classes in a 1 to many relationship
- Create generic selector for Select() while using Entity Framework
- Get list items upto match in C#
- Linq Expression to Select a Field
- Include method in LINQ is used for Left Join?
- icon of uploaded file in gridview
- Nhibernate 3.0 LINQ: Problem returning to IQueryable (non generic version) - doesn't allow ToList()
- Update all objects except one in a collection using Linq
- Adding a second Join with LINQ
- LINQ show result as array
- Multi-delimited string to list of objects using linq and lambdas
- How to get text from LINQ2SQL query?
- Wrong select query generated with Entity Framework (mysterious extra column)
- LINQ query to combine two string[] arrays
- How to set date format "yyyy-MM-dd hh:mm" in linq?
- Assign Mapped Object to Expression Result in LINQ to Entities
- LINQ operation with ternary operation causing tests to fail if logic is swapped
- What's the difference between these LINQ queries?
- is there any reason to use entity SQL over Linq?