System.NotSupportedException: Collection was of a fixed size.
I am getting the above error when adding an entity to my db set. The entity has no collections of a fixed size, and I cannot figure out why this is happening
29 Replies
This is the config I apply to the entity, also cannot spot anything incorrect here to cause the error
try changing ClothingItems to ICollection
did try that - still get the same error
pretty weird soultion but i found this on github issues
wow that was it
fuck me
thank you very much sir
could you link me that issue please ? @blueberriesiftheywerecats
GitHub
Support fixed-size collections · Issue #24497 · dotnet/efcore
Description Error message is not that descriptive as it could be for a case when fixed size collection (Array) is used for a navigation property. It'd be nice to be pointed to the problematic n...
I think it means that you somewhere changed your entities without saving it?
you can use AsNoTracking method to prevent that
FYI, you should probably not be calling AddAsync as that is specifically for hi-lo ID generation
and i'm concerned that you're touching the change tracker by hand
hi-lo ID generation?
Hi/Lo algorithm
Hi/Lo is an algorithm and a key generation strategy used for generating unique keys for use in a database as a primary key. It uses a sequence-based hi-lo pattern to generate values. Hi/Lo is used in scenarios where an application needs its entities to have an identity prior to persistence. It is a value generation strategy. An alternative to Hi...
basically, a method of generating IDs that needs to talk to the database before you actually want to add the row
normally adding entities in EF doesn't talk to the database at all so calling AddAsync isntead of Add is not necessary
so u suggesting calling Guid.New...() explicitly?
no, i'm suggesting not using AddAsync
unless you're using hilo key generation, just call Add
so Add is not using that algorithm, just generating new Id?
add does not generate IDs
unless you are using hilo
i mean whenever I Add and than Save it generates Id
yes, saving generates the IDs
adding does not
adding only adds the entities to the change tracker
but if I save I would still use that algoritm?
what?
I mean when using SaveChanges is it just generating new Id or using that algorithm?
all i'm saying is this: if you are using hi-lo key generation, call AddAsync. in all other types of key generation, call Add
it is using the algorithm you specified in your model
if you didn't tell it to use hi-lo, it isn't using hi-lo
alr
async methods are only useful when the call has to do some I/O that the CPU has to wait for, so if there is no I/O being done async just adds overhead and wastes performance
what would this mean exactly? the entity I am adding I am creating just before calling that AddAsync method, so I'm not sure what exactly is being tracked here?
This is all that is being done prior to adding it to the dbcontext
also interesting regarding the
Add
vs AddAsync
, will switch to using Add
You can check which entities are not yet saved by calling this.context.ChangeTracker.Entries()
It doesnt have to be that enitity that you work with
fyi,
upload
and createdUpload
are the exact same object
EF doesn't copy it