KarlRKaiser
KarlRKaiser

Reputation: 365

EF Core - possible to reference DBSets as string variables or properties?

Writing a table-driven data mapping engine, which references its tables as variables/properties.

But how to execute methods on List objects when they are identified as the value of a property?

...for Example, in literal code, with a dbSet "Customers" and dbContext "dbc", one could insert a Customer record with :

dbc.Customers.Add(Customer);

But if "Customers" is identified as a variable...

var dbSetName = "Customers"

...is there some way to abstractly execute the same record insertion, e.g.:

dbc.[dbSetName].Add(Customer)

Upvotes: 0

Views: 60

Answers (1)

bricelam
bricelam

Reputation: 30415

Just use the Add method on DbContext.

dbc.Add(Customer);

Upvotes: 1

Related Questions