I have the following query, I'd like to sum the NULL value also. Some TimeSheet don't records in TimeRecord and some tr.TimeIn and tr.TimeOut are NULL.The query select only TimeSheet that has reords in TimeRecord. How I can have it select everything, and sum up the NULL value as well. So, the SUM of NULL will be just zero.
I've got a subquery that returns the most recent value from a child table. In some cases the subquery returns nothing. The query below fails at runtime because the inferred type of MemberPrice is decimal and is not nullable. [code]...
I'm having trouble figuring out what to do with the bolded part, when there are no nodes to return.If there are no image tags inside the <images> tag, i get an "Object reference is not set to an instance of an object".I have been searching and searching for an answer but can't find one.
Dim orders = From o In xmlLinq.Descendants("order") Select New With { _ .orderID = o.Attribute("id").Value, _
I have a DataSet where I need to filter the collection where one of the date columns is not null.
How do you term this in LINQ?
This is what I have so far but there is a compiler error on the w.CompletedDate field in the Where clause.
Dim completed = From ins In InspectionDataset.Inspection.AsEnumerable _ Where (Function(w) w.CompletedDate IsNot Nothing) _ Order By ins.Field(Of DateTime)("UpdatedDate")
I have also tried it the below way but the compiler will not allow the DBNull comparison.
Dim completed = From ins In Inspection.AsEnumerable _ Where ins.Field(Of DateTime)("CompletedDate") <> DBNull.Value _ Order By ins.Field(Of DateTime)("UpdatedDate")
I am finding this weird issue. When I do this > activities.Where(Function(a) (Not a.IsDeleted And a.ParentId = 100) It returns an in-memory query & when I try opening it up, it throws a object not set exception. This only happens when there were no items which satisfied the condition. Shouldn't it be returning an empty set? When there are items satisfying the condition, then it returns a list & works all good.
I've got what I think is a working left outer join linq query but I'm having problems with the select because of null values in the right hand side of the join.[code]I want to return all of e and one column from c called tClassCode. I was wondering what the syntax would be. As you can see I'm using vb.net.[code]If i remove the c.tClassCode from the select the query runs without error. So i though perhaps i needed to do a select new but i don't think i was doing that correctly either.
From r In ReceiptLines Where r.RECEIPT.RECEIPTDATE >= _reportStartDate And r.RECEIPT.RECEIPTDATE <= _reportEndDate
[Code].....
I am fetching all departments and their sales, average, count from the ReceiptLine, Receipt, ReceiptDiscount tables. The problem i am facing is, if i remove where discount > 0, I am getting null exception. But if I include that, then I only get sales that has discount. How would I write query that bring all sales less discount (if it has one).
If I have a datatble column set as int16 but rows can contain null values for this column. How do i write the linq query. I keep getting an error null value exception. Dim query = From n In resultstable.AsEnumerable Where n.value is dbnull.value does n't work.
I've got a table that caches calculated values for certain dates. I want to use LINQ to select all rows where the calculated value fields are null.But when I use isNothing I get an error that LINQ can't translate this into T-SQL. Is there a way to select null values with link, like this...?
Dim var = From rec As Record In myDataContext.Records Where IsNothing(rec.calculatedValue) Select rec
Other posts on stackoverflow mostly discuss how to avoid or check for null values with LINQ.
Note: I can't just set cacluatedValue's default to -1 to flag records whose calculated value has not been set (and then select those records) because I run queries that sum/average the calculated values. Selecting nulls seems cleaner and less bug-prone.
Dim sizings = From a In db.Sizings Where a.Customer.ID = customer.ID Select a If sizings.Any Then .....
The sizings.Any line is throwing a null reference exception. I thought I was meant to use .Any to determine if there were any rows returned?isnothing(sizings) returns false.
Edit - Resolution:Don't use null objects in the LINQ Query!
I'd like to take all suggestion either in C# or VB.NET.I have a DB diagram like the image below. I also include the database script here [URL]In the Students table, CountryId and RoomId column are allowed null. Because some records do not have info about room and country yet.Also, some students do not have essays.I'm doing a joint query with all tables. I want to select all students to project the result like this:Wanted query result.
Here's my current query that gives the result like the image below:
Dim db As New DBDataContext Dim query = From st In db.Students _ Join c In db.Countries On c.Id Equals st.Id _ Join r In db.Rooms On r.Id Equals st.RoomId _
[code].....
current query result I got only one result back because I have (2) William NoMan record in every table. But I don't get anything about others, like (3) Sync Master who has everything but RoomId.What do I need to modify the query above so it will give me all students like in the wanted query image above?
've got a function that takes two parameters (a delegate and an integer) and then creates a LINQ MethodCallExpression, which it uses to gets the results:
Public Delegate Function CompareTwoIntegerFunction(ByVal i1 As Integer, ByVal i2 As Integer) As Boolean Public Function Test(ByVal pFunc As CompareTwoIntegerFunction, ByVal i1 As Integer, ByVal
Private _PurchaseDelivery as PurchaseDelivery Protected Overrides Sub InsertItem(ByVal index As Integer, ByVal item As PurchaseDeliveryItem)
[Code]....
Which is inside a class which overrides a custom list base. The code is occassionaly throwing an unhandled exception, System.NullReferenceException, on this line when used in production:
If _PurchaseDelivery IsNot Nothing AndAlso _PurchaseDelivery.DefaultSKUBinID.HasValue Then
DeafultSKUBinID is declared as an Integer? (Nullable Int) in the PurchaseDelivery class. I cannot see what might be causing this error, why would this be returning an error?
When I put a break point to the last if clause in the sub ("If (backOrder < 0) Then", see below) it runs until the break point, if I put the break point further below, I get the following error:
Cannot insert the value NULL into column 'OrderID', table 'WHM.dbo.OrderDetails'; column does not allow nulls. INSERT fails. The statement has been terminated.
I've discovered first hand that it only happens when prodqty is bigger then qtyOnStock, thus executing the if clause.
The code:
Private Sub NCOSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NCOSubmit.Click Dim sqlText As String = ""
I am trying to create a treeview in VB.net, the data has to be loaded from MSAccess 2010 database. When I try to run this program I get error : Argument Null Exception was unhandled, 'column' argument cannot be null and the program crashes. I have pasted the code as under:
Imports System.Data.OleDb Public Class frmRating Private Sub frmRating_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles
I have a listbox on my xaml form that I bound to a List(Of MyType) property. I populated this list like so:
Dim fields As List(Of CheckableFields) = New List(Of CheckableFields) Using context As ITIPEntities = New ITIPEntities() Try[code]....
Now I'm at the point where the user selects the fields they want included in a report and I need to iterate over the required fields. This is my linq query:
For Each checkedField In _requiredFields If checkedField.IsChecked Then If checkedField.FieldData IsNot Nothing AndAlso checkedField.FieldData.Trim IsNot String.Empty Then[code].....
Forgive my ignorance on this.I have this LINQ Query:Dim ngBikersDataContext As New CarBikeWalkDataContext
bikersList = (From c In ngBikersDataContext.Reg_Bikers _ Order By c.L_Name _ Select New Bikers() With { _ .BikerID = c.BikerID, _ .F_Name = c.F_Name, _
[Code]...
with the error "Overload resolution failed because no accesible 'Select' accepts this number of arguments." Over the "NEW" I get an error " ')'expected."
I have some code which gets child items for a menu via the GetChildren function which takes a list of menuData: Dim builtMenu As New List(Of MenuData)(_rawData.FindAll(Function(item) item.GroupingID = 0))
For Each menuData As MenuData In builtMenu If menuData.Children IsNot Nothing Then menuData.Children.AddRange(GetChildren(menuData)) End If Next
If I check if menudata.children isnot nothing, it always is nothing because the GetChildren function is yet to run (providing the child items, which do exist). If I remove this check and just have this code:
Dim builtMenu As New List(Of MenuData)(_rawData.FindAll(Function(item) item.GroupingID = 0))
For Each menuData As MenuData In builtMenu menuData.Children.AddRange(GetChildren(menuData)) Next
Then I am presented with a Object reference not set to an instance of an object error on menuData.Children.AddRange(GetChildren(menuData))
We are doing a query against an in-memory collection of LINQ data objects. The wrinkle is that we are ordering by a column in a related table whose records have not necessarily been loaded yet (deferred loading:)
Dim oPkgProducts = _ From b In oBillPkg.BillProducts _ Where b.Successful.GetValueOrDefault(Common.X_INDETERMINATE) = _
The pattern I'm trying to avoid is checking if a string (normally a control's text value) is null/empty, and if it is, comparing it using Contains to a field in my data. Obviously the field isn't hard-coded into my extension, neither is the object type.What I've got works perfectly in Linq to Objects, but I get the generic run-time error "LINQ to Entities does not recognize the method 'System.String Invoke(GenericQueryHelper.Customer)' method, and this method cannot be translated into a store expression." when using an entity framework model.
Here's what I have:
<System.Runtime.CompilerServices.Extension()> Public Function CompareAndFilter(Of T)(source As System.Linq.IQueryable(Of T), expressionField As System.Linq.Expressions.Expression(Of System.Func(Of T, String)), compareTo As String)
[code]....
I want my usage to look something like this:
Dim results = repository.Customers.CompareAndFilter(Function(c) c.FirstName, searchText)
I do need to get this running against a SQL database really, as it is filtering results, so I don't want to be doing that in memory.
How do I add ROW_NUMBER to a LINQ query or Entity? How can I convert this solution to VB.NET?
[Code]...
I'm having trouble porting that last line. I have been unable to locate a VB.NET example. I'm actually not looking for any paging functionality like the example provides, just good old-fashioned Row_Number(Order By X) row index.