Reputation: 1
I'm working with Entity Framework and I need to change the name of the table at runtime. Please any idea about how can I do that. Exmaple in my database I have a table "Invoice" and 'InvoiceXXXX" (XXXX is the year of the invoice Invoice2010 for the invoice of 2010). I just want to have in the entity "Invoice" but I would like to have the option of using the same classe to work with the "Invoice2010" table. Thanking
Maria
That is only an example. I need to be enable to change the name of the table at runtime....
Upvotes: 0
Views: 918
Reputation: 1973
I also was researching the answer to this. For many reasons, it can be desirable to have multiple contextual tables based on a common schema, so I understand your question.
Try this article at
http://theruntime.com/blogs/jacob/archive/2008/08/27/changing-table-names-in-an-orm.aspx
The author there went to pains to try and solve this for both LinqToSql, and Entity Framework. At my workplace we're testing his solution right now, but it certainly looks workable.
Upvotes: 2
Reputation: 5405
Look into the Multiple Entity Sets per Type (MEST) feature of the Entity Framework. It doesn't have designer support, so you'll have edit the .edmx file by hand, but otherwise it pretty much works.
Upvotes: 0
Reputation: 54618
It would be bad practice to segment your invoice by table names. Properly normalized table would have a DateTime
column that can indicate the year of the invoice (more likely this already exists as the Invoice Date Issued).
If you need to grab only a specific years invoices, that is what SQL is specifically designed for.
Upvotes: 2