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

Exception using LazyLoading When sharing same .Net Type among multiple owned types #11972

Closed
AmilaDotDev opened this issue May 11, 2018 · 1 comment

Comments

@AmilaDotDev
Copy link

AmilaDotDev commented May 11, 2018

{System.NullReferenceException: Object reference not set to an instance of an object.
   at lambda_method(Closure , QueryContext , Person , Object[] )
   at Microsoft.EntityFrameworkCore.Query.Internal.IncludeCompiler._Include[TEntity](QueryContext queryContext, TEntity entity, Object[] included, Action`3 fixup)
   at lambda_method(Closure , TransparentIdentifier`2 )
   at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Boolean& found)
   at lambda_method(Closure )
   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ResultEnumerable`1.GetEnumerator()
   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.<_TrackEntities>d__17`2.MoveNext()
   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
   at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Boolean& found)
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass15_1`1.<CompileQueryCore>b__0(QueryContext qc)
   at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source)
   at OwnedTypes.NotWorking.Program.Main(String[] args) in ...\OwnedTypes\OwnedTypes.NotWorking\Program.cs:line 26}

Steps to reproduce

Please take a look at the solution in the following repo.
https://github.com/amilarox1/OwnedTypes

The solution has two projects. OwnedTypes & OwnedTypes.NotWorking

OwnedTypes.NotWorking project is using Microsoft.EntityFrameworkCore.Proxies 2.1.0-rc1 and all the navigation properties are virtual (including owned types) and this causes the above exception when queriying data from the database.

Please check the ReadMe.md in the repo for more information

Further technical details
EF Core version: 2.1.0-rc1
Database Provider: SqlServer 2.1.0-rc1
Operating system: Win10
IDE: Visual Studio 2017 15.6.6

@ajcvickers
Copy link
Contributor

@amilarox1 Thanks for filing this. Turns out it was a duplicate of the same root cause, so closing this as a duplicate of the original issue (but using your title for that one!)

@ajcvickers ajcvickers removed this from the 2.1.0 milestone May 12, 2018
ajcvickers added a commit that referenced this issue May 12, 2018
Fixes #11972

The fix is to allow proxies (derived types) in the optimization check.
@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
@ajcvickers ajcvickers removed their assignment Sep 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants