新手问题 - SQL检查约束 - 应该很简单,但它是我的错 [英] newbie question - SQL check constraints - should be simple but it's outwitted me

查看:53
本文介绍了新手问题 - SQL检查约束 - 应该很简单,但它是我的错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在试图找出如何替换在审核案例文件时使用的基于Excel的笨拙数据条目"模板"。 数据本质上是一个表,我们将把它转储到SQL Server中,以便集中并广泛使用。 

I'm trying to figure out how to replace an awkward Excel-based data entry 'template' used in reviewing case files.  The data is, essentially, a single table, and we're going to dump it in to SQL Server so it is centralized and widely available. 

在Excel文件中有几个使用数据验证将响应限制为是/否/未知的列,在SQL文件中,我已在所有列上创建了检查约束,需要三个值中的一个(是/否/未知),以及所有这些
列的默认值为"未知"。 首先,如何将这些约束推送/拉入EF或Linq to SQL模型。 我尝试过的任何东西似乎都没有出现在设计师中。 其次,一旦我能够看到约束,数据
绑定控件(Winforms或WPF)如何理解约束?

In the Excel file there are several columns that use Data Validation to limit the response to Yes/No/Unknown, and in the SQL file I have created a check constraint on all of those columns, requiring one of the three values (Yes/No/Unknown), and all those columns have a default of Unknown.  First, how do I push/pull those contraints through into an EF or Linq to SQL model.  Nothing I've tried seems to show up in the designers.  Second, once I'm able to see the constraints, how does a data bound control (Winforms or WPF) understand the contraint?

感谢您考虑这一点。

 

推荐答案

我不认为EF支持Check Constraints(至少开箱即用) 。

I don't think EF supports Check Constraints (atleast Out of the Box).

执行此操作的一种方法是为Constraint值创建引用表,并在Main表中创建外键。这样,引用表就变成了第一类实体,也可以用于绑定。

One way to do this is to create reference tables for the Constraint values, and create foreign keys in the Main table. This way, the reference table becomes a first-class entity, and can used for binding too.


这篇关于新手问题 - SQL检查约束 - 应该很简单,但它是我的错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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