RBear
RBear

Reputation: 383

How to map many tables with same schema to one class

Is there a way in entity framework or linq to sql classes to map one class to many different tables with the same schema. For example if I have a database with thousands of tables for different stocks. All of the tables have the same columns. Is there a way I could have a base type class that could be used for mapping the data to an object. I obviously dont want to make thousands of different classes with just the table name being the difference. Also the tables change, ie new ones are added and names of some change from time to time. So idealy I would just have one class and when I request it I could pass in a symbol and it would map it to the correct table.

Thanks

Upvotes: 0

Views: 326

Answers (1)

John Saunders
John Saunders

Reputation: 161773

That seems to be a silly database design, and it's going to cause you more problems than just this. If all the data are the same, then they should be in a single table. Whether you partition the physical storage of that single table is a low-level implementation issue, not somthing that should show up in the schema.

I don't even know how you'd go about telling EF that you had added a new table, and it's to treat it like all the others. It just doesn't make too much sense.

Upvotes: 3

Related Questions