Q: How to store a multidimensional array (matrix) in the Entity Framework in ASP.NET Core It is possible to store an matrix of values ​​in the Entity Framework which needs to be dynamic depending on the number of attributes for a specific stock quantity.
For example:
A product variant such as: T-Shirt Size: XL, Color: Green, Material: Cottom, having 5 units.
Matrix of values

Example of a matrix used in a ecommerce

But this matrix of values ​​needs to be flexible to store any kind of values ​​and any number of attributes.

Is it possible?
Regards

A: There are three ways I see this being implemented and the choice depends on what do you want to be able to do with this data.

*

*JSON property

Just store all these values in a json object and serialize it into a string value. EF can handle storing it with no issue. When you actually need it—unwrap it and use the data to display the options to the user. Optionally, you can write your own conversion between a JSON object and something like a Dictionary<string, object>, so you will end up with your items having a property, that has a dictionary of custom properties and their values.
Note that working with this data would be pretty costly, as you would need to unwrap JSON all the time (even if you write custom SQL queries to do it on the database side, without pulling all the data back to the application layer).


*Actual model-level concepts

You can store your custom properties as a seperate class model (so that they get their own table), and then introduce a third model (another table in the database), which would store a link to the specific property, a link to the specific object that has that property, and a value you assigned to it.
This will probably be more efficient than the first approach.
Now you can leave it as is, do the casting to the dictionary again (otherwise it'll be a list of objects and accessing a property by name application-side would be a chore), or even write some wrappers, casting retrieved objects into dynamics and dynamics back to your data model classes.


*Document-oriented database

Well, this is the proper way of storing this kind of data. There is a lot of options here, but you will pretty much have to adapt the tools to your needs. Microsoft's own CosmosDB has an API in .NET, but I'm not sure if there is a way to use EF for this. BrightstarDB has a provider for EF, so there is this option. The most efficient approach would be, perhaps, to implement your own solution, jointly using the SQL and NoSQL databases.
This will be the way to go, if you definitely need this kind of functionality and you want it to be clean and fast. Or you just want to write a bunch of wrappers and converters.
