You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// relevant bits of entities...
class Company {
public string name { get; set; }
}
class Show {
public string title { get; set; }
public Company company { get; set; }
}
"search" is a string, posted from a web page.
// this works ...
var qTotal = _context.Shows.Include( e => e.company ).Include( ... others ... );
qTotal = qTotal.Where( e => e.title.Contains(search) || e.company.name.Contains(search) );
// this throws null exception
var qTotal = _context.Shows.Include( e => e.company ).Include( ... others ... );
qTotal = qTotal.Where("title.Contains(@0) || company.name.Contains(@0)", search);
System.NullReferenceException: Object reference not set to an instance of an object.
at lambda_method(Closure , TransparentIdentifier`2 )
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.<SkipIterator>d__30`1.MoveNext()
at System.Linq.Enumerable.<TakeIterator>d__24`1.MoveNext()
at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.<_TrackEntities>d__15`2.MoveNext()
at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
From the VS2015 debug window:
Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommandBuilderFactory: Information: Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT [it].[id], [it].[companyid], [it].[slug], [it].[subtitle], [it].[timestamp], [it].[title], [it.company].[id], [it.company].[addressid], [it.company].[name], [it.company].[slug], [it.company].[timestamp], [p].[id], [p].[addressid], [p].[name], [p].[slug], [p].[timestamp]
FROM [Shows] AS [it]
LEFT JOIN [ProductionCompany] AS [it.company] ON [it].[companyid] = [it.company].[id]
LEFT JOIN [ProductionCompany] AS [p] ON [it].[companyid] = [p].[id]
ORDER BY [it].[companyid], [it].[id]
Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommandBuilderFactory: Information: Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT [s].[id], [s].[ownerid], [s].[permission], [s].[role], [s].[timestamp], [s].[userId]
FROM [Staff<Show>] AS [s]
INNER JOIN (
SELECT DISTINCT [it].[companyid], [it].[id]
FROM [Shows] AS [it]
LEFT JOIN [ProductionCompany] AS [it.company] ON [it].[companyid] = [it.company].[id]
) AS [it1] ON [s].[ownerid] = [it1].[id]
ORDER BY [it1].[companyid], [it1].[id]
Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommandBuilderFactory: Information: Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT [e].[id], [e].[ProductionCompanyid], [e].[allDayEvent], [e].[description], [e].[duration], [e].[masterRecurid], [e].[notes], [e].[recurState], [e].[showid], [e].[start], [e].[timestamp], [e].[venueid]
FROM [Events] AS [e]
INNER JOIN (
SELECT DISTINCT [it].[companyid], [it].[id]
FROM [Shows] AS [it]
LEFT JOIN [ProductionCompany] AS [it.company] ON [it].[companyid] = [it.company].[id]
) AS [it0] ON [e].[showid] = [it0].[id]
ORDER BY [it0].[companyid], [it0].[id]
Microsoft.EntityFrameworkCore.Query.Internal.SqlServerQueryCompilationContextFactory: Error: An exception occurred in the database while iterating the results of a query.
System.NullReferenceException: Object reference not set to an instance of an object.
at lambda_method(Closure , TransparentIdentifier`2 )
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.<_TrackEntities>d__15`2.MoveNext()
at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
System.NullReferenceException: Object reference not set to an instance of an object.
at lambda_method(Closure , TransparentIdentifier`2 )
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.<_TrackEntities>d__15`2.MoveNext()
at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
Exception thrown: 'System.NullReferenceException' in Microsoft.EntityFrameworkCore.dll
The text was updated successfully, but these errors were encountered:
After a closer look, I'm closing this as "my bad" ... the problem I have encountered appears to be EF7 related. The null was from a nullable field having a null value, but the query was not being translated into SQL, it was being processed post-query.. going over to the EF repo to bug them!
"search" is a string, posted from a web page.
From the VS2015 debug window:
The text was updated successfully, but these errors were encountered: