In the database that I am working with, there is a table for “dynamic user-created attributes”. This table has the schema seen below …
Id BoxId DateCreated
84 10231 2024-05-17 03:36:54.5333333
85 10232 2024-08-05 02:27:25.9800000
The Id
is a primary key, BoxId
is a foreign key to a Box
table.
What the software does is, it adds additional columns to the table as a user creates a new “attribute”. So after several attributes have been created by an end-user at run-time, the table schema might look like the following …
Id BoxId DateCreated AttrMyString AttrMyLong AttrMyDate X_AttrKeywords AttrKeywords
85 10232 2024-08-05 02:27:25.9800000 NULL NULL NULL [] NULL
The columns are simple types like int, nvarchar.
Because these columns are impossible to know at compile-time, the base entity framework entity definition only contains the first three columns, as seen below …
public class BoxAttribute
{
public long Id { get; set; }
public long BoxId { get; set; }
public DateTime DateCreated { get; set; }
}
My question is: is there a way to use a DbSet
to query this table, so that I can use other entity framework functionality, but also provide access to that row’s other columns? Maybe like a dictionary of key-value for the non-entity columns?
I’m currently using a raw SQL query on the table and creating my own dictionary of the non-entity columns.