score:0
i found the solution. applied if on whole new column not just on the specific column in the joining table (rate
column) because the null is not originated from the rate
column, it is originating from an empty bookingcharge
record against a booking
(attached to the query as a column .totalcharges
) therefore whole column should undergo the if statement (coalescence).
.totalcharges = if(b.bookingcharges.sum(function(o) o.rate) <> nothing, b.bookingcharges.sum(function(o) o.rate), 0)
thanks to namrehs and this so answer.
score:2
try using the if() operator:
dim q = (from b in _db.bookings
select new with {
.bid = b.id
.totalcharges = b.bookingcharges.sum(function(o) if(o.rate,0))
}).tolist()
if that doesn't work, maybe try something like this:
dim q = (from b in _db.bookings
select new with {
.bid = b.id
.totalcharges = b.bookingcharges.where(function(r) r.rate isnot nothing).sum(function(o) o.rate)
}).tolist()
Source: stackoverflow.com
Related Query
- Exclude null values while summation by specific column in a left joined table using LINQ
- Why NULL values are excluded while selecting values from table
- How to prevent to change other column values into table while updating single column using Entity Framework?
- Check specific column in list for duplicates, skip null or empty values
- Linq on DataTable: select specific column into datatable, not whole table
- Joining two tables with LINQ while also returning null records from the second table
- linq to sql left join, need to check for null for right table
- LINQ LEFT JOIN not working on NULL values
- EF Code First comparing null values generates strange query
- How to concat strings in LINQ while properly dealing with NULL values
- Show in gridView Specific column of Table using Entity Framework 6.0
- LINQ Left join on nullable column giving null reference exception
- LINQ, Left Join, Only Get where null in join table
- In a table a column datatype is varchar, retrieve only those values of the column which are number / numeric using linq to sql
- asp.net mvc Linq exclude values from other table
- Dealing with a null column in LINQ while concatenate to a string
- How to return null in a GroupBy statement when one of the values in the non-key column contains null?
- Cannot insert the value NULL into column 'ProductId', table 'ProductDB.dbo.Brand';
- MVC3. How to select additional column from joined table and send them all to View?
- LINQ exclude null while selecting into enumeration
- Convert string to decimal within LINQ Average function while handling possible null values
- c# linq how to check for null values in the same column that i need to be not null
- ASP.net Getting Max Date of database Date column How to avoid Null in Date Column C# My code Attached
- Code First EF: While searching database table is it possible to retrieve list of items it has in DataModel?
- Get data from a table after joining based on null value of joined table using LINQ
- Select values from one table based on specific value of another table Linq
- C# Linq join table, where left table might be null
- How to return or display distinct values only from a specific column using EF Core?
- How to sum the values of a specific column attribute of individual rows returned using a LINQ expression? (C#)
- How to perform a left join when joined field is null or 0
More Query from same tag
- Do I have to close the SQL Connection manually if I use Linq?
- Get cell values from DataGrid
- How to find an element in Dictionary with LINQ
- Set several class values using LINQ expression
- C# - Help with LINQ
- Is ToArray() optimized for arrays?
- How to convert class properties of single type to list of that type
- DataTable Error - Can't CopyToDataTable()
- how do i group a List<int> and return a List<int>
- How to parse a JArray into JObjects, get the first 4 letters of a string of the JObjects and save them back in a JArray
- Linq to find pair of points with longest length?
- left outer join in LINQ
- How to filter based on the previous filtering
- SELECT COUNT in LINQ to SQL C#
- How to pass in a list of generic objects into a method?
- Unable to add a record because of dynamicproxy issue with c# and linq
- Linq to Entities - group by on multiple joined tables
- Equivalent of For Loop in LINQ
- Order of operations when creating new object with .Select()
- DataGridView shows type and not the value
- Perform a LINQ query without using NotMapped properties in EF
- Normalize ConcurrentDictionary of arrays
- How can I get a List<int> from LINQ to XML that produces List<List<int>>?
- Linq query group by weight
- How to get array overlaps using LINQ?
- How to dynamically contruct / change a part of LINQ statement
- select from a list with field name and field value with linq (similar to select command)
- distinct list LINQ Query
- Adding an Ienumerable list in ViewModel which will be Enumerated In View
- Use inner join in linq