I'm trying to create a generic function that will be used to access multiple tables in my database. Is there a way to used pluralised (pluralized for the non-British!) table names with my generic function.
I may be thinking about this the wrong way (fairly new to generics/templates), but here's my code (Db
is just a global var for access to my database):
public void UpdateMyTables<TEntity>() {
// string plural = EntityObject<TEntity>.GetTableName(); // OR SOMETHING SIMILAR??
IEnumerable<EntityType> entitiesToUpdate = Db.<TEntity>; // Obviously doesn't work because TEntity is not a table name, it's an object type
foreach(<TEntity> e in entitiesToUpdate) {
e.MyColumn = "A string that I'm updating all these fields with";
}
}
So my question is: do I need to do some hackery to get the pluralised table name, or is there a function designed to return this (like GetTableName), or should I come at this from a different angle?
I also found a link that would help with the manual conversion here: Pluralising in mvc
Hugs and kisses and thanks in advance...