dj-nitehawk / MongoDB.Entities

A data access library for MongoDB with an elegant api, LINQ support and built-in entity relationship management
https://mongodb-entities.com
MIT License
543 stars 69 forks source link

The collection type 'MongoDB.Entities.Many' is abstract, an interface, or is read only, and could not be instantiated and populated #202

Closed criss02-cs closed 1 year ago

criss02-cs commented 1 year ago

I'm trying to update a model with asp.net core but when i pass the json below it throws a new NotSupportedException : The collection type 'MongoDB.Entities.Many' is abstract, an interface, or is read only, and could not be instantiated and populated { "name": "Acqua", "halfDamage": [ { "id": "64498df00820884387341f72", "name": "Fuoco" } ] } HalfDamage is a Many property, i have to insert more elements inside that, but i don't know how to do

dj-nitehawk commented 1 year ago

this sounds like you should use embedded entities for HalfDamage property instead of referenced entities. but if you must make it a referenced relationship, you should do it without exposing your data entities to the frontend world. frontend models should be mapped to data entities and vise versa.

here's a sample project showing how i'd personally do it: OneToManySample.zip