constraints

Options for Unique field in Entity Framework - navigation property to dbSet?

一曲冷凌霜 提交于 2019-11-30 16:12:55
问题 After much research it seems Entity Framework 4.4 doesn't support Unique constraints. Yes it can & should be done at the database, but I'd much prefer it happen in model validation so the warning to user is prettier. It would be ideal for programmers to be able to decorate the property with a [Unique] attribute and it should be possible somehow, eg.: public class UserGroup { public int UserGroupID { get; set; } [Required] [Unique] public string Name { get; set; } [Required] public string

Oracle Unique Constraint based on column value

无人久伴 提交于 2019-11-30 14:33:39
I have the following unique constraint dup_Checklist_QNum UNIQUE (QUESTION_NO, IS_ACTIVE) I am trying to prevent two questions having the same question number while being active (IS_ACTIVE value = 1). All seemed fine until I had to rev a question for the second time. QUESTION_NO=1, TEXT="Have you..", REV=1, IS_ACTIVE=0 QUESTION_NO=1, TEXT="Have you..", REV=2, IS_ACTIVE=0 <-- This should be ok but constraint was violated QUESTION_NO=1, TEXT="Have you..", REV=3, IS_ACTIVE=1 QUESTION_NO=1, TEXT="Have you..", REV=3, IS_ACTIVE=1 <-- This should be throw constraint exception I need the constraint to

Getting table metadata in MySQL

陌路散爱 提交于 2019-11-30 12:08:11
问题 I'm trying to find out how to get the following constraint information from a table in MySQL 5.0: primary key foreign keys and table references unique columns What is the syntax of the query or queries to do so? I have a feeling I'm close with this, but there is no example. 回答1: The SHOW COLUMNS command will show you the primary key and unique columns for a table. As for foreign keys, you could use something like the SHOW CREATE TABLE command which will output the DDL statements needed to

Why doesn't an interface work but an abstract class does with a generic class constraint?

自闭症网瘾萝莉.ら 提交于 2019-11-30 11:59:44
The code below shows a generic class with a type constraint ( Pub<T> ). The class has an event that it can raise allowing us to pass a message to subscribers. The constraint is that the message must implement IMsg (or inherit from IMsg when it's is an abstract class). Pub<T> also provides a Subscribe method to allow objects to subscribe to the notify event if and only if the object implements IHandler<IMsg> . Using .NET 4, the code below shows an error on baseImplementer.NotifyEventHandler stating that: "No overload for 'IHandler<IMsg>.NotifyEventHandler(IMsg)' matches delegate 'System.Action

How do I define a generic class that implements an interface and constrains the type parameter?

我的未来我决定 提交于 2019-11-30 11:44:02
问题 class Sample<T> : IDisposable // case A { public void Dispose() { throw new NotImplementedException(); } } class SampleB<T> where T : IDisposable // case B { } class SampleC<T> : IDisposable, T : IDisposable // case C { public void Dispose() { throw new NotImplementedException(); } } Case C is the combination of case A and case B. Is that possible? How to make case C right? 回答1: First the implemented interfaces, then the generic type constraints separated by where : class SampleC<T> :

Why is some ordering enforced in generic parameter constraints?

ぐ巨炮叔叔 提交于 2019-11-30 11:08:18
When defining a generic type parameter's constraints, we have to put class() at the front and new() at the end, for example. Why is this, why can't I put my constraints in any order? Are there any other restrictions on ordering besides class / struct first, new() at the end? Example: protected T Clone<T>() where T : class, ICopyable<T>, new() Eric Lippert There's no particular reason why that order was chosen. The chosen order goes from more general to more specific, which I suppose is a reasonably nice property. As for the question "why require an order at all?", it's simply easier on the

How to add constraints on inherited properties in a grails domain sub-class

最后都变了- 提交于 2019-11-30 10:57:35
Here's what I'd like to do: class A { String string static constraints = { string(maxSize:100) } } class B extends A { static constraints = { string(url:true) } } So class A should have some constraints and B should have the same plus additional constraints on the same property. I couldn't get that to work though and I can imagine that it would clash with the Table-per-Hierarchy concept. So I tried to work around that problem by introducing a Command object with class B's constraints which can be validated in the constructor of class B. However it seems that Command objects can only be used

iOS开发技巧(系列十五:autolayout自动布局)

徘徊边缘 提交于 2019-11-30 10:06:52
autolayout自动布局技术在iOS6就已经推出了,但是因为很多人一开始不习惯使用xib编程,而是坚持使用代码布局控件,所以autolayout并没有普及的太快。但是现在随着越来越多的人开始使用xib,怎样适配不同屏幕的尺寸和横竖屏,成了亟待解决的问题,好在两年前就已经推出并且日臻完善的xib autolayout技术可以完美的解决。 首先需要说下需求:需要登陆LoginViewController视图View上面的控件居中显示。 下面我就以一个简单的例子,来简要说明使用autolayout的小技巧, (1)拖拉一个View到LoginViewController.xib的视图上面,调整高度为300,我下面都称其为MiddleView吧,如下图所示, 为了让图片垂直 居中 显示,我们可以通过键盘的上(↑)下(↓)按键移动View。 (2)拖两个UITextField和一个UIButton到View上面,同时设置了MiddleView的背景色为LightGray,如下图所示, (3)给MiddleView添加约束,使其水平和竖直居中,先选中MiddleView,然后按照下图操作, (4)给MiddleView添加宽高(width and height)的约束,上面仅仅添加水平和垂直居中,会有警告,这是因为添加的约束还不够,如下图所示,添加宽高的约束, (5

How to set parameters' sum to 1 in constrained optimization

為{幸葍}努か 提交于 2019-11-30 09:58:56
Here's the code (I'm sorry if it's so long, but it was the first example I had); I'm using the CVaR example from CreditMetrics package by A. Wittmann and DEoptim solver to optimize: library(CreditMetrics) library(DEoptim) N <- 3 n <- 100000 r <- 0.003 ead <- rep(1/N,N) rc <- c("AAA", "AA", "A", "BBB", "BB", "B", "CCC", "D") lgd <- 0.99 rating <- c("BBB", "AA", "B") firmnames <- c("firm 1", "firm 2", "firm 3") alpha <- 0.99 # correlation matrix rho <- matrix(c( 1, 0.4, 0.6, 0.4, 1, 0.5, 0.6, 0.5, 1), 3, 3, dimnames = list(firmnames, firmnames), byrow = TRUE) # one year empirical migration

How do I detect if a table exist? MySql

二次信任 提交于 2019-11-30 09:39:03
问题 I was suggested to do this SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema = 'mydb' AND table_name='ApprovePost'; However it is not reliable and cause me errors on several versions of mysql on windows and linux. Maybe there is another way. Does anyone know? This issue is I can do create table if not exists but I do a second pass to add the FK constraint. In my SQL dump I see > 130 contains on a single table. The table only has 6 columns, only two of these