score:3
Your max function is trying to return an Int64. The overload of Max you are using is defined here on MSDN. You'll see that it takes a parameter Func<TSource, long> selector
. This is your lambda expression and says that you'll give it a TSource and it will return a long (ie Int64). What your function is doing is when x.Value is null returning a null value which is of course not valid to as an Int64.
In this case you should be able to use something like:
x=> x.Value!=null?x.Value:Int64.Minvalue
This means that if x has a value it returns that and otherwise returns the minimum possible value which will only ever be the max if everything is null.
I should disclaim that this code is untested but should give you the right idea.
edited: I originally was assuming that this was a nullable long but it turns out there are overloads that support that so I now assume that x is not a nullable long, just looks a bit like one if you squint int eh right way.
Source: stackoverflow.com
Related Articles
- LINQ Source Code Available
- Linq ForEach - Returning cannot assign 'void' to an implicitly-typed local variable
- Assign multiple tables to single class in linq table mapping
- Cannot convert source type to target type List<KeyValuePair> Linq
- creating Linq to sqlite dbml from DbLinq source code
- CLRSQL Aggregate function. LINQ Code works within CLR Function but cannot be deploy within Aggregate
- Cannot build the Test project for LINQ IQueryable Toolkit (IQToolkit) - Code 9009
- How to assign multiple LINQ Include() statements to a variable for code re-use?
- Make access possible to dynamic table LINQ EF6 Code First
- LINQ Cannot assign void to Implicitly Typed variable
- source code for LINQ 101 samples
- Linq assign values from one table into another
- Cannot assign LINQ query to variable
- How to reinsert data from one table onto itself using LINQ in code migration?
- How to join one row to every row in source table using LINQ
- Does Linq in Entity Framework code first use SQL or does it get the whole table first?
- Cannot convert source type 'System Linq IQueryable<decimal>' to target type decimal
- The entity or complex type '' cannot be constructed in a LINQ to Entities query, three table outer join
- Sum field in sub query in Linq giving Cannot Assign Method error
- Can I assign the result of a Linq query to the source variable of the same query?
- c# Linq or code to extract groups from a single list of source data
- error Cannot implicitly convert type when Join Merged Data Table using Linq
- How to assign LINQ Query to a variable and then use it later in the code
- How to update Linq result with in the list, without assign other data table process itself get another one result
- Entity Framework Code First - The entity or complex type cannot be constructed in a LINQ to Entities query
- cannot get related table with Include in edmx and LinQ
- Convert string[] to int[] in one line of code using LINQ
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- Value cannot be null. Parameter name: source
- Distinct in Linq based on only one field of the table
- Linq IQueryable Generic Filter
- Linq to Sql IsNull replacing NULL FK with existing FK
- How can I get an XElement's .InnerText value in Linq to XML?
- Assign an object to the class from within
- Replace Duplicates with unique string in Dictionary<string,list<object>>
- Unable to determine SQL type for... when creating tables with LinQ
- Newbie issue with LINQ in vb.net
- Cast result to custom class with System.Linq.Dynamic.Core
- Is there some way of "peeking" a MoveNext(), or how can I get past this fencepost issue?
- linq, calculating the count of counts
- Return one Element from List using LINQ
- confusion between entity framework and linq
- How can I sort my Linq list?
- LINQ to populate treeview based upon grouping
- How do you get data across multiple tables with EF and linq?
- C# console input
- check if item contain in list
- using short-lived datacontext with LINQ to SQL
- How to get total results count before .Take() - but when using .Take()
- C# - Group by common properties to object