C
C#4mo ago
marco

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
No description
29 Replies
marco
marcoOP4mo ago
This is the config I apply to the entity, also cannot spot anything incorrect here to cause the error
marco
marcoOP4mo ago
No description
blueberriesiftheywerecats
try changing ClothingItems to ICollection
marco
marcoOP4mo ago
did try that - still get the same error
blueberriesiftheywerecats
pretty weird soultion but i found this on github issues
Hi everyone, I just solved it... well... it's strange solution but it worked for me. I was watching this.context.ChangeTracker.Entries() and it was full of unchanged properties.
I just added this.context.ChangeTracker.Clear() before running the code I posted above... well... it worked...
Hi everyone, I just solved it... well... it's strange solution but it worked for me. I was watching this.context.ChangeTracker.Entries() and it was full of unchanged properties.
I just added this.context.ChangeTracker.Clear() before running the code I posted above... well... it worked...
marco
marcoOP4mo ago
wow that was it fuck me thank you very much sir could you link me that issue please ? @blueberriesiftheywerecats
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...
blueberriesiftheywerecats
I think it means that you somewhere changed your entities without saving it? you can use AsNoTracking method to prevent that
Jimmacle
Jimmacle4mo ago
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
blueberriesiftheywerecats
hi-lo ID generation?
Jimmacle
Jimmacle4mo ago
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...
Jimmacle
Jimmacle4mo ago
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
blueberriesiftheywerecats
so u suggesting calling Guid.New...() explicitly?
Jimmacle
Jimmacle4mo ago
no, i'm suggesting not using AddAsync unless you're using hilo key generation, just call Add
blueberriesiftheywerecats
so Add is not using that algorithm, just generating new Id?
Jimmacle
Jimmacle4mo ago
add does not generate IDs unless you are using hilo
blueberriesiftheywerecats
i mean whenever I Add and than Save it generates Id
Jimmacle
Jimmacle4mo ago
yes, saving generates the IDs adding does not adding only adds the entities to the change tracker
blueberriesiftheywerecats
but if I save I would still use that algoritm?
Jimmacle
Jimmacle4mo ago
what?
blueberriesiftheywerecats
I mean when using SaveChanges is it just generating new Id or using that algorithm?
Jimmacle
Jimmacle4mo ago
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
Jimmacle
Jimmacle4mo ago
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
marco
marcoOP4mo ago
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?
marco
marcoOP4mo ago
This is all that is being done prior to adding it to the dbcontext
No description
marco
marcoOP4mo ago
also interesting regarding the Add vs AddAsync, will switch to using Add
blueberriesiftheywerecats
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
Jimmacle
Jimmacle4mo ago
fyi, upload and createdUpload are the exact same object EF doesn't copy it
Want results from more Discord servers?
Add your server