Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null reference when using Take #5112

Closed
jazzonaut opened this issue Apr 19, 2016 · 2 comments
Closed

Null reference when using Take #5112

jazzonaut opened this issue Apr 19, 2016 · 2 comments

Comments

@jazzonaut
Copy link

jazzonaut commented Apr 19, 2016

The following query:

var results = (from call in db.Calls
                select new
                {
                    IpkStatusName = call.StatusNavigation.Name
                }).Take(10);

Produces the following exception:

Exception thrown: 'System.NullReferenceException' in Microsoft.EntityFrameworkCore.dll
Additional information: Object reference not set to an instance of an object.

  at lambda_method(Closure , ValueBuffer )
   at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.UnbufferedEntityShaper`1.Shape(QueryContext queryContext, ValueBuffer valueBuffer)
   at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.<_ShapedQuery>d__3`1.MoveNext()
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)

Using build 20620 from the 19th or April.

@smitpatel
Copy link
Member

Does following work?

var results = (from call in db.Calls.Include(c => c.StatusNavigation)
                select new
                {
                    IpkStatusName = call.StatusNavigation.Name
                }).Take(10);

@jazzonaut
Copy link
Author

Sorry, the entity of the StatusNavigation property was not properly bound in the model, it is all working fine now!

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants