开发者

How to handle Foreign key for optional field in .NET

开发者 https://www.devze.com 2022-12-24 20:45 出处:网络
What is the best way to handle following situation? A dropdown(for master table) is optional in a partic开发者_运维技巧ular form. But, In database table the field is constrained with foreign key. If

What is the best way to handle following situation?

A dropdown(for master table) is optional in a partic开发者_运维技巧ular form. But, In database table the field is constrained with foreign key. If user don't select from dropdown then It creates problem because of foreign key.

One solution is to create default option in master table and use it in case of blank selection. but in dropdown, we need to handle this to show on top. Is it perfect solution? Is there any other optimized solution for this?

Thanks


If it's required in the database, then it should not be optional on the front end. Either change the database, or change the front end. A foreign key constraint alone should not make this mandatory, you may want to make the field nullable.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号