是否可以在 EF7 中使用 fluent API 添加 CHECK 约束? [英] Is it possible to add CHECK constraint with fluent API in EF7?

查看:33
本文介绍了是否可以在 EF7 中使用 fluent API 添加 CHECK 约束?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 Entity Framework 7 中使用 fluent API 添加 CHECK 约束?

Is it possible to add CHECK constraint with fluent API in Entity Framework 7?

我需要实现这样的目标:

I need to acheive something like this:

...
ADD CONSTRAINT CK_SomeTable_SomeColumn CHECK (SomeColumn >= X);

如果解决方案是特定于提供者的也没关系 - 我只针对 MsSqlServer(至少现在是这样).

It is ok if solution is provider-specific - I am targeting MsSqlServer only (at least now).

推荐答案

从 EF 7.0.0-rc1 开始,使用 fluent API 是不可能的.

As of EF 7.0.0-rc1, it isn't possible with the fluent API.

您可以在迁移中手动定义约束

You can define the constraint manually in the migration

migrationBuilder.Sql("ALTER TABLE SomeTable ADD CONSTRAINT CK_SomeTable_SomeColumn CHECK (SomeColumn >= X);");

这篇关于是否可以在 EF7 中使用 fluent API 添加 CHECK 约束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆