I need to publish an "Orders" table to a web site, but for reasons beyond this scope, it is not possible for the web app to have direct access to the company's database.The solution is to create the same "Orders" table in another database (on a remote IIS server) and export the original orders (rows) to it. For this I'm using the EF 5 and AutomaticMigrationsEnabled = true
The original "Orders" table has a key column named "OrderNo", where "IsIdentity = Yes". I would like the web "Orders" table to also have its "OrderNo" as a key column, so that I can use the "Find" method to locate and update the rows, but here is the problem:
I cannot set the "OrderNo" to be an identity, since it must keep the original "OrderNo" value, however after running "PM> update-database" the "Orders" table is created with the "OrderNo" column "IsIdentity" set to "Yes". If I set it to "No", by opening the table in design mode, the next Migrations will give an error.
After trying some options, I found that if I add another "dummy" column with a [Key] attribute on it, the table is created with 2 keys and none has the identity set to "Yes". In this way, it is possible to insert new rows keeping the original "OrderNO" value and update rows using the "Find" method. Naturally, the "Find" method now requires 2 parameters, the dummy column (whose value is always 0 (zero)) and the original "OrderNo".
Although it is working, I know this is not the correct way to do it and I'm wondering if someone knows how to do it.
NOTE: I know I can find the entity using a query, which does not requires the "OrderNo" to be a key but I read the "Find" (using primary keys) has some advantages.