{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/11450","repository_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore","labels_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/11450/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/11450/comments","events_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/11450/events","html_url":"https://github.com/aspnet/EntityFrameworkCore/issues/11450","id":309266781,"number":11450,"title":"Unable to create a null constant value in collection assignments","user":{"login":"TomWouters","id":34544633,"avatar_url":"https://avatars0.githubusercontent.com/u/34544633?v=4","gravatar_id":"","url":"https://api.github.com/users/TomWouters","html_url":"https://github.com/TomWouters","followers_url":"https://api.github.com/users/TomWouters/followers","following_url":"https://api.github.com/users/TomWouters/following{/other_user}","gists_url":"https://api.github.com/users/TomWouters/gists{/gist_id}","starred_url":"https://api.github.com/users/TomWouters/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TomWouters/subscriptions","organizations_url":"https://api.github.com/users/TomWouters/orgs","repos_url":"https://api.github.com/users/TomWouters/repos","events_url":"https://api.github.com/users/TomWouters/events{/privacy}","received_events_url":"https://api.github.com/users/TomWouters/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-03-28T08:26:00Z","updated_at":"2018-03-28T14:21:36Z","closed_at":null,"author_association":"NONE","body":"I am currently developing a framework, with extendable tables/relations etc...\r\nThe way it is done is by creating classes, Having extension records (eg class 1 has an extra field named x ), compiling the combination of the 2 to a new class, and creating new relationship types, to those new extended classes.  Then compiling those as a definition for entity framework.  This works perfectly.\r\nNow there is an edge case where I'm requesting  an iqueryable, which contains class x with a collection of Y, which contains a class x, with a collection of y, which contains a class x, ....\r\n\r\nIn order to avoid endless recursion I want to stop after the second iteration of the collection.  so basically:\r\n\r\nX.Col[Y].X  where in the final x, col[y] would be null or an empty list (don't really care either way, but it should not be translated into a sql select query).\r\n\r\nThere is a prerequisite requirement to entity framework, which dictates that if you have a new X with property assignments, if there is another new x with a new definition, all the properties of the first initialization definition have to be present.\r\n\r\nSo for me this means I have to create an expression with:\r\n\r\nNew class X(), Y = Select (z over table y)\r\n\r\nand the second time:\r\nNew class X(), Y = null.\r\n\r\n\r\nThis is where the issue lies.  Entity framework doesn't accept the y = ((List<Y>)null).\r\n\r\nThe solution would be to not have to repeat the variable assignments if the class has been instantiated before (so EF should set null values to properties which aren't set), or there should be a way to create an expression where you can say y =  ((List<Y>)null) or a similar expression which has the same result.\r\n\r\n\r\nThe \"remarkable\" part is that empty assignments work in the base table, but once you reach a collection, and try to do null assignments inside, entity framework doesn't want to create those empty types.\r\n\r\n\r\nIf you are seeing an exception, include the full exceptions details (message and stack trace).\r\n\r\n```\r\nException message:\r\n\r\nUnable to create a null constant value of type 'System.Collections.Generic.List`1[[dbasics.CompanyData.Model.DebtorOpenItem, dbasics.CompanyData.Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]'. Only entity types, enumeration types or primitive types are supported in this context.\r\n\r\nStack trace:\r\n\r\n   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.ConstantTranslator.TypedTranslate(ExpressionConverter parent, ConstantExpression linq)\r\n   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)\r\n   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)\r\n   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MemberInitTranslator.TypedTranslate(ExpressionConverter parent, MemberInitExpression linq)\r\n   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)\r\n   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)\r\n   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.ConditionalTranslator.TypedTranslate(ExpressionConverter parent, ConditionalExpression linq)\r\n   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)\r\n   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)\r\n   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MemberInitTranslator.TypedTranslate(ExpressionConverter parent, MemberInitExpression linq)\r\n   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)\r\n   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)\r\n   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input)\r\n   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input, DbExpressionBinding& binding)\r\n   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, DbExpression& source, DbExpressionBinding& sourceBinding, DbExpression& lambda)\r\n   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SelectTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)\r\n   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod)\r\n   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)\r\n   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)\r\n   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)\r\n   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.UnarySequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)\r\n   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod)\r\n   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)\r\n   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)\r\n   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)\r\n   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MemberInitTranslator.TypedTranslate(ExpressionConverter parent, MemberInitExpression linq)\r\n   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)\r\n   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)\r\n   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input)\r\n   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input, DbExpressionBinding& binding)\r\n   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, DbExpression& source, DbExpressionBinding& sourceBinding, DbExpression& lambda)\r\n   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SelectTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)\r\n   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod)\r\n   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)\r\n   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)\r\n   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)\r\n   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.Convert()\r\n   at System.Data.Entity.Core.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1 forMergeOption)\r\n   at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.<GetResults>b__6()\r\n   at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)\r\n   at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.<GetResults>b__5()\r\n   at System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute[TResult](Func`1 operation)\r\n   at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)\r\n   at System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()\r\n   at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()\r\n   at dbasics.UnitTest.Storage.Sqlite.DatabaseTest.IQueryableTestStorageTest() in D:\\tfs\\net\\dev\\src\\dbasics.UnitTest.Storage.Sqlite\\DatabaseTest.cs:line 274\r\n```\r\n\r\n### Steps to reproduce\r\nInclude a complete code listing (or project/solution) that we can run to reproduce the issue.\r\n\r\nBecause of the compilation system mentioned above, it is virtually impossible for me to easily reproduce the code, so instead I'll dump the expression tree in a simple form.\r\n\r\n.Call System.Linq.Queryable.Select(\r\n    .Call .Constant<System.Data.Entity.Core.Objects.ObjectQuery`1[ns_FullTypes_.Gen_Debtor]>(System.Data.Entity.Core.Objects.ObjectQuery`1[ns_FullTypes_.Gen_Debtor]).MergeAs(.Constant<System.Data.Entity.Core.Objects.MergeOption>(AppendOnly))\r\n    ,\r\n    '(.Lambda #Lambda1<System.Func`2[ns_FullTypes_.Gen_Debtor,dbasics.CompanyData.Model.Debtor]>))\r\n\r\n.Lambda #Lambda1<System.Func`2[ns_FullTypes_.Gen_Debtor,dbasics.CompanyData.Model.Debtor]>(ns_FullTypes_.Gen_Debtor $item)\r\n{\r\n    .New dbasics.CompanyData.Model.Debtor(){\r\n        Code = $item.Code,\r\n        CodeOriginal = $item.CodeOriginal,\r\n        CreatedByContextId = $item.CreatedByContextId,\r\n        AddressVisit = .If ($item.AddressVisit == null) {\r\n            null\r\n        } .Else {\r\n            .New dbasics.CompanyData.Model.DebtorAddress(){\r\n                Code = ($item.AddressVisit).Code,\r\n                CodeOriginal = ($item.AddressVisit).CodeOriginal,\r\n                CreatedByContextId = ($item.AddressVisit).CreatedByContextId\r\n            }\r\n        },\r\n        DebtorOpenItems = .Call System.Linq.Enumerable.ToList(.Call System.Linq.Enumerable.Select(\r\n                $item.DebtorOpenItems,\r\n                .Lambda #Lambda2<System.Func`2[ns_FullTypes_.Gen_DebtorOpenItem,dbasics.CompanyData.Model.DebtorOpenItem]>))\r\n    }\r\n}\r\n\r\n.Lambda #Lambda2<System.Func`2[ns_FullTypes_.Gen_DebtorOpenItem,dbasics.CompanyData.Model.DebtorOpenItem]>(ns_FullTypes_.Gen_DebtorOpenItem $item)\r\n{\r\n    .New dbasics.CompanyData.Model.DebtorOpenItem(){\r\n        Code = $item.Code,\r\n        DocumentsReferenceCode = $item.DocumentsReferenceCode,\r\n        ActualDeliveryDate = $item.ActualDeliveryDate,\r\n        DocumentsFilesReferences = $item.DocumentsFilesReferences,\r\n        CodeOriginal = $item.CodeOriginal,\r\n        CreatedByContextId = $item.CreatedByContextId,\r\n        Debtor = .If ($item.Debtor == null) {\r\n            null\r\n        } .Else {\r\n            .New dbasics.CompanyData.Model.Debtor(){\r\n                Code = ($item.Debtor).Code,\r\n                CodeOriginal = ($item.Debtor).CodeOriginal,\r\n                CreatedByContextId = ($item.Debtor).CreatedByContextId,\r\n                AddressVisit = .If (($item.Debtor).AddressVisit == null) {\r\n                    null\r\n                } .Else {\r\n                    .New dbasics.CompanyData.Model.DebtorAddress(){\r\n                        Code = (($item.Debtor).AddressVisit).Code,\r\n                        CodeOriginal = (($item.Debtor).AddressVisit).CodeOriginal,\r\n                        CreatedByContextId = (($item.Debtor).AddressVisit).CreatedByContextId\r\n                    }\r\n                },\r\n                DebtorOpenItems = (System.Collections.Generic.List`1[dbasics.CompanyData.Model.DebtorOpenItem])null\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\n\r\nthe issue lies with the second assignment of debtoropenitems. (DebtorOpenItems = (System.Collections.Generic.List`1[dbasics.CompanyData.Model.DebtorOpenItem])null)\r\n\r\n\r\nPartial code listings, or multiple fragments of code, will slow down our response or cause us to push the issue back to you to provide code to reproduce the issue.\r\n\r\n\r\n### Further technical details\r\nEF version: 6.2.0\r\nDatabase: Provider:System.Data.SQLite.EF6\r\nOperating system:  Windoes 10\r\nIDE: Visual Studio 2017 15.6\r\n"},"comment":{"url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/comments/376904640","html_url":"https://github.com/aspnet/EntityFrameworkCore/issues/11450#issuecomment-376904640","issue_url":"https://api.github.com/repos/aspnet/EntityFrameworkCore/issues/11450","id":376904640,"user":{"login":"smitpatel","id":1528107,"avatar_url":"https://avatars0.githubusercontent.com/u/1528107?v=4","gravatar_id":"","url":"https://api.github.com/users/smitpatel","html_url":"https://github.com/smitpatel","followers_url":"https://api.github.com/users/smitpatel/followers","following_url":"https://api.github.com/users/smitpatel/following{/other_user}","gists_url":"https://api.github.com/users/smitpatel/gists{/gist_id}","starred_url":"https://api.github.com/users/smitpatel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smitpatel/subscriptions","organizations_url":"https://api.github.com/users/smitpatel/orgs","repos_url":"https://api.github.com/users/smitpatel/repos","events_url":"https://api.github.com/users/smitpatel/events{/privacy}","received_events_url":"https://api.github.com/users/smitpatel/received_events","type":"User","site_admin":false},"created_at":"2018-03-28T14:21:36Z","updated_at":"2018-03-28T14:21:36Z","author_association":"CONTRIBUTOR","body":"This issue was moved to aspnet/EntityFramework6#508"}}
{"actor":{"display_login":"smitpatel"}}