简体   繁体   中英

Update table based on ID other than Primary Key

Is it possible to use an ID other than the primary key to identify database records in ASP.NET MVC?

We're currently looking at updating an old system into .NET, and the original database structure has two IDS: sqlID and then page ID . At the moment, the website pages are called from a database based on a page ID , so they don't change if the database is migrated etc, whilst the sqlID can change as and when needed based on database migrations and such.

So, my question is, when doing an Edit action for example, rather than clicking "Edit" in a table and the ID it uses to find that record being a primary key, is there a way to do it based on another column?

Thanks

If I understand your question, you want to sort your database by another key. You can do this by going to the Keys property of your table, and selecting the other column as your primary key. Take care to ensure your new primary key is unique though. If you do a query on the same table after changing the primary key you should see it is sorted by the new key. Hope this helps. I don't think there would be any changes if you backup and restore the database, but that would depend on your internal dependencies (constraints) between this table and other tables. I haven't tested it so be careful - I don't want you to break a database to test my theory :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM