gpt4 book ai didi

entity-framework - 如何向 ADO.NET 实体添加约束?

转载 作者:行者123 更新时间:2023-12-04 12:15:01 24 4
gpt4 key购买 nike

我知道如何在 ADO.NET 实体中将一组字段标记为主键,但我还没有找到声明唯一约束或检查约束的方法。

设计器或框架上是否缺少此功能?

最佳答案

v4.0 中的 ADO.NET 实体中不存在对唯一键/约束的支持,请参阅“one-to-one association on a foreign key with unique constraint”的答案,Diego B Vega 说:

I know for sure we haven't added support for unique keys other than primary keys in 4.0.



但是,他确实提供了一种可能的解决方法/hack(附带所有正常警告):

As you are probably aware of, it is often possible to “lie” to Entity Framework and tell it in the SSDL, for instance, that some unique key is the primary key. I reckon this would work very well if the actual primary key is an surrogate key (i.e. an IDENTITY column that was added for this purpose) and you don’t even have to map it in the model.

关于entity-framework - 如何向 ADO.NET 实体添加约束?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1963829/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com