constraints

UNIQUE CONSTRAINT on a column from foreign table in SQL Server 2008

I have two tables: create table [dbo].[Main] ( [ID] [int] identity(1,1) primary key not null, [No] [int] not null, [Sign] [char](1) not null ) create table [dbo].[Names] ( [ID_Main][int] primary key not null, [Name][nvarchar](128) not null, constraint [FK_Main_Users] foreign key ([ID_Main]) references [dbo].[Ma...

Namespace constraint with generic class declaration

I would like to know if (and if so how) it is possible to define a namespace as a constraint parameter in a generic class declaration. What I have is this: namespace MyProject.Models.Entities <-- Contains my classes to be persisted in db namespace MyProject.Tests.BaseTest <-- Obvious i think Now the decleration of my 'BaseTest' cla...

how to get object that triggered constraint violation in entity framework

Hi everyone. Here is the situation: Lets's imagine we have table A in the database and we've created Entity model for that table. Let's also imagine that there are several Uniqeu and Foreign constraints in that table. Now let's do the following: load more than 1 record from that table into the context. Change some objects to make som...

setting more than one RouteConstraint on route parameter

here are code I'm using to do, but compiler says: An anonymous type cannot have multiple properties with the same name context.MapRoute("RouteName", "statics/category/{fileName}", new { controller = "myController", act...

Java - How to reset JLabel constraints after initializing it ?

I initialize a JLabel in Java frame like this : contentPane.add(myLabel, cc.xywh(1, 1, 31, 6, CellConstraints.DEFAULT, CellConstraints.BOTTOM)); But before showing the JFrame i make a small condition which if returns true i want to set myLabel to be set to DEFAULT instead of BOTTOM, but i can't find anyway except redefining it again l...

Conditional logic on Generic Type Constraints

I'm trying to write an automocking extension of Unity. While it would be much easier to use a Windsor subdependency resolver and RhinoMocks I'm forced by the business to use Unity and Moq. I haven't found an existing solution that uses Moq and I've found out why. Moq can't generate mocks from just a Type parameter, which makes Unity ex...

sql server drop default syntax error

Hi, I am trying to drop the default value on a bit column, I have set it wrong and I want to do it again correctly. However, when I write: ALTER TABLE Person ALTER COLUMN tsHomePref DROP DEFAULT; I get a 'incorrect syntax near keyword default error' and I don't know why I want to drop the column and then build it again ALTER TABLE...

db indexes application - best practice

When developing large systems (hundreds of tables) Do you create the indexes (and to lesser extend the other constraints in the DB) when you create the entities (tables), or wait for the system to be running (may be private Beta) to decide where to put the indexes? ...

Generic type parameter constraint based on other type parameter in the same definition

I have type hierarchy defined like this: interface IMyClass { } interface IBase1<T> { } interface IBase2<T> { } interface IMyDerived1 : IBase1<IMyClass> { } class Base1<T, U> : IBase1<T> where U : IBase2<T> { } class Base2<T, U> : IBase2<T> where U : IBase1<T> { } class Derived1<T, U> : Base1<T, U>, IMyDerived1 where T...

sql constraints

Why do i have to drop all constraints (keys in general) before i can drop a table in sql server. I dont understand why this would be necessary if I have permissions to drop the table and the know how to do it why not drop all constraints for me? Is there some sort of technical or database design reason for this? ...

Dynamic list constraint on Alfresco

Hi, I'm trying to follow the examples provided in this post, to create a dynamic list constraint in Alfresco 3.3. So, I've created my own class extending ListOfValuesConstraint: public class MyConstraint extends ListOfValuesConstraint { private static ServiceRegistry registry; @Override public void initialize() { ...

What is this "_ifbk" constraint doing in my table?

I'm working on a Rails web application with a MySQL database. I'm using migrations to modify the schema. I've just run into a problem wherein I'm getting an invalid record error on inserting a new record. The relevant tables: users id | name | email | ... academic_records id | scholar_id | gpa | ... academic_records.scholar_id is a ...

Is there any way to constrain a type parameter to EITHER a reference type OR a nullable value type?

It'd be nice if I could define a method like this: public T GetItem<T>() where T : null { if (someCondition<T>()) return someCalculation<T>(); else return null; } Then I could use this on reference types (e.g., object, string) as well as nullable value types (e.g., int?, double?): anything that can be assigned ...

ActiveRecord: how to find constraints?

I'm kind of new to ActiveRecord (using CastleProject) and gaining knowledge step by step. Now I'm running into another situation. I've got a Media class that is used in some other classes: Content, Case and Service. Now when I want to delete a Media class, I want to check if there are any constraints with the previous named classes. I...

How do i detect if a table exist? MySql

-edit- OMG Ponies answered this correctly. I cant accept his answer because for now it is just a comment. 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 wi...

Constructor constraint on generic types or simply check for constraint within my generic type constructor?

I have a generic class DirectorySource<T> which depends on an interface IDirectorySearch<T>. Both are generics and have the same type constraint: public class DirectorySource<T> where T : IDirectoryEntry { } public interface IDirectorySearcher<T> where T : IDirectoryEntry { } So, for instance, when I want a source to manipulate grou...

Entities field lenght constraint

Hi everyone, I'm currently working with Entities (using visual studio 2008, FW 3.5 SP1). I created my entities from the database, and everything is ok, except that my lenght constraints on the string fields are not enforced. Browsing the internet, I found out that this is quite normal (see this blog post), and that Entities sends the da...

Sql Server - Constraint - Allow to set column A only if column B is null and vice-versa

Is there a way to add a constraint in SQL Server 2008 that will verify that if a user try to enter a value in a column A, it can only if column B is null and vice-versa Example if A is NULL, B can have a value if B iS NULL, A can have a value A and B can't have value at the same time ...

Questions about implementing Domain class relationships & constraints in Grails.

Using ArgoUML, I very quickly created this trivial representation of a few Domain classes (Person, Store, Product) and their relationships. I'm struggling with the implementation of the relationships. Below was my initial approach for the Person domain, but it seems that I am missing something important. class PersonToPerson { ...

Anti-constraint on C# generics

Inspired by Phil Haack's attempt on null or empty coalescing, I'm trying to write a couple of extension methods for the string object, as well as on the IEnumerable<T> interface, to simplify null or emtpy ckecking. However, I'm running into problems: when I'm attempting to call the string version of AsNullIsEmpty, the compiler treats my ...