在实体框架唯一约束 [英] Unique constraint in Entity Framework
本文介绍了在实体框架唯一约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何才能设置实体(实体框架)的一些属性是唯一的?一种可能性是,使其主键,但是这不是我想要的。
How can one set some attribute in Entity (Entity Framework) to be unique? One possibility would be to make it primary key but that's not what I want.
推荐答案
实体框架不支持唯一的密钥所以唯一的办法是设置唯一约束/索引在数据库中。它不能保证唯一性的应用程序,当您尝试插入/更新记录,但该异常将被解雇,如果你尝试非唯一的值保存到数据库中。
Entity framework doesn't support unique keys so the only way is to set the unique constraint / index in the database. It will not ensure uniqueness in the application when you try to insert / update records but the exception will be fired if you try to save non unique value to the database.
这篇关于在实体框架唯一约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文