score:0
[fact]
public void getsum()
{
var classes = new[]
{
new testclass {amount = null, id = 1},
new testclass {amount = 1, id = 0}
};
var sum1 = classes.where(i => i.id > 1)
.select(i => i.amount)
.aggregate((double?)null, (a, b) => a.hasvalue && b.hasvalue ? a + b : a ?? b);
var sum2 = classes.select(i => i.amount)
.aggregate((double?)null, (a, b) => a.hasvalue && b.hasvalue ? a + b : a ?? b);
assert.null(sum1);
assert.notnull(sum2);
}
Source: stackoverflow.com
Related Query
- Simple Linq expression Sum - Not returning null value for empty list
- LINQ syntax where string value is not null or empty
- LINQ - Returning value of a property of an object that is not null
- Linq query NOT returning null when empty
- SQL Query to LINQ for MVC with SUM and IS NOT NULL
- Could not evaluate expression - Linq Query just returning null
- LINQ to SQL - Expression checking for null could not be translated
- Perform a linq expression for 'contains' with searching through a list for 'like' not exact matches
- EF Core: The LINQ expression could not be translated for a nested List with Generic StartsWith() Expression
- How to handle null in LINQ query for nullable int if value not found
- Using LINQ to check for anything in a list that is not null or blank
- C# Linq to query a List to see if a value is empty or null
- Sum in Linq to Sql not returning a value
- Linq Expression returning null rather than empty set
- Error: "An expression tree lambda may not contain a null propagating operator" for Linq with from
- Linq query returning null when trying to pass a column value from list object
- C# LINQ select from where value is not contained in array / list
- LINQ, simplifying expression - take while sum of taken does not exceed given value
- C# 6 null conditional operator does not work for LINQ query
- How to assign empty string if the value is null in linq query?
- How to return null if using SingleOrDefault() and searching a list of numbers for a number not in list?
- Returning empty linq expression
- Handle null in LINQ sum expression
- linq query for varchar field not returning any results
- Expression to get LINQ with Contains to EF for SQL IN() where on entities child's property equals value
- Using DefaultIfEmpty in Linq - problem substituting a null value for a default value
- Generic expression for where clause - "The LINQ expression node type 'Invoke' is not supported in LINQ to Entities."
- Check DateTime for null in linq expression
- Lambda expression to return one result for each distinct value in list
- Embed a test for null in a single LINQ expression
More Query from same tag
- How to create breadcrumb for parent and children?
- C# LINQ - Retrieve multiple attributes from single element, convert to structured (non-xml) text
- System.Linq.Dynamic.Core.DynamicExpressionParser.ParseLambda throwing System.NotSupportedException
- Linq idea on date calculation
- Get unique object by key in MongoDB driver
- Add cdata tags to xml docuemnt
- Get nested UserRoles from User table
- Use Linq instead of Icomparable
- c# LINQ get Attribute value from XElement
- Using LINQ's SkipWhile over string properties
- How to bind LINQ data to dropdownlist
- Reading an XML file and create a list of objects that match the XML content
- C# Linq Select Rows Where ID Equals ID in CSV
- Linq Contains issue: cannot formulate the equivalent of 'WHERE IN' query
- LINQ query to get recursive category structure and products of each category
- Flatten Dictionary with a List and return Custom IEnumerable
- comparing Decimal(9,3) column value in Linq
- Select specific columns in a generic repository function
- Min() and Max() or single oldschool foreach?
- Convert SQL to C# Entity Framework Linq
- SQL IN statement in Linq for NHibernate
- Expose dictionary setter property for linq usage
- LINQ where list within a list contains a value
- Get list of titles from xml files
- How can I include more than one level deep in a LINQ query?
- How parse a string as linq exprssion?
- How to return an array of grouped items?
- How to know if Array FileInfo[] contains a file
- Count across multiple columns in LINQ
- Inverse of OfType in Linq?