I have query like below:
```c#
var exist = await _context.ProductGroups.AnyAsync(pg => pg.ProductGroupTypeId == groupTypeId && pg.Title == title);
and query throw exception:
Exception message:
System.NotSupportedException: Collection was of a fixed size.
at System.ThrowHelper.ThrowNotSupportedException(ExceptionResource resource)
at Microsoft.EntityFrameworkCore.Metadata.Internal.ClrICollectionAccessor3.Add(Object instance, Object value)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NavigationFixer.AddToCollection(InternalEntityEntry entry, INavigation navigation, IClrCollectionAccessor collectionAccessor, Object value)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NavigationFixer.ToDependentFixup(InternalEntityEntry dependentEntry, InternalEntityEntry principalEntry, IForeignKey foreignKey)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NavigationFixer.InitialFixup(InternalEntityEntry entry, ISet
1 handledForeignKeys, Boolean fromQuery)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.NavigationFixer.StateChanged(InternalEntityEntry entry, EntityState oldState, Boolean fromQuery)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntryNotifier.StateChanged(InternalEntityEntry entry, EntityState oldState, Boolean fromQuery)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityGraphAttacher.PaintAction(EntityEntryGraphNode node)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityEntryGraphIterator.TraverseGraph(EntityEntryGraphNode node, Func2 handleNode)
at Microsoft.EntityFrameworkCore.DbContext.SetEntityState[TEntity](TEntity entity, EntityState entityState)
at ProductGroupRepository.AddProductGroup(ProductGroupEntity productGroup) in \ProductGroupRepository.cs:line 20
at SociaSoft.Bss.Infrastructure.Products.ProductGroupService.<AddProductGroupAsync>d__3.MoveNext() in \ProductGroupService.cs:line 26
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter
1.GetResult()
at Products.ProductGroupCommandHandler.
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Controllers.ProductGroupsController.
Controllers\ProductGroupsController.cs:line 50
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Builder.RouterMiddleware.
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
```
EF Core version: 2.0.0
Database Provider: Microsoft.Data.Sqlite 2.0.0
Operating system: Windows 10
IDE: Visual Studio 2017
@mo-esmp What do your entity types look like? Do they have fixed-size collections for navigation properties?
Here is my entity:
```c#
public class ProductGroupEntity : BaseEntity
{
public string Title { get; set; }
public bool IsActive { get; set; }
public byte[] Icon { get; set; }
public int? ParentId { get; set; }
public ProductGroupEntity Parent { get; set; }
public int ProductGroupTypeId { get; set; }
public ProductGroupTypeEntity ProductGroupType { get; set; }
public ICollection<ProductGroupProvinceEntity> ProductGroupProvinces { get; set; }
public ICollection<ProductEntity> Products { get; set; }
}
```
Query works fine with SQL Server provider and for testing purpose I use Sqlite in memory provider. I think this error is related to Icon
property.
@mo-esmp Thanks for the additional info. Unfortunately we still are not able to reproduce this issue. Could you provide a full code listing or project that demonstrates the issue?
@ajcvickers I couldn't reproduce issue in a sample but still occurring in my solution and I didn't find any reason for that or what I'm doing wrong. here is my simplified solution repo url: SqliteDemo.
just run test in AdminProductGroupTests.cs file and error will occur in
https://github.com/mo-esmp/SqliteDemo/blob/ebe0adde69c52e72ea38418b8df75ec719812218/src/Infrastructure/Products/ProductGroup/ProductGroupRepository.cs#L25
@mo-esmp In DataContextSeed the code is creating a new array of ProductGroupEntity:
```C#
ProductGroups = new[]
{
new ProductGroupEntity
...
EF navigation properties cannot be fixed sized arrays. so this needs to be changed to something like:
```C#
ProductGroups = new List<ProductGroupEntity>
{
new ProductGroupEntity
...
With this change the test passes for me.
Most helpful comment
@mo-esmp In DataContextSeed the code is creating a new array of ProductGroupEntity:
```C#
ProductGroups = new[]
{
new ProductGroupEntity
...
With this change the test passes for me.