Weird, it looks ok according to the docs: http://www.nhforge.org/doc/nh/en/index.html#toolsetguide-s1-2
Could you try using the generated hbm.xml with a test like this? http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/28/create-and-update-database-schema.aspx If that doesn't generate the check constraint, try asking in the NHibernate forums... On Mar 5, 9:15 am, Juan Fernández <[email protected]> wrote: > Sorry, here it is > > <?xml version="1.0" encoding="utf-16"?> > <hibernate-mapping auto-import="true" default-lazy="false" > xmlns:xsd="http://www.w3.org/2001/XMLSchema" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xmlns="urn:nhibernate-mapping-2.2"> > <class name="LMMobileCMS.Server.ServiceLibrary.AbstractServiceObject, > LMMobileCMS.Server.ServiceLibrary" table="ServiceObjectBase"> > <id name="Id" access="property" column="Id" type="Int32" > unsaved-value="0"> > <generator class="native"> > </generator> > </id> > <property name="ParentId" access="property" type="System.Int32, > mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > insert="false" update="false"> > <column name="ParentId" unique-key="UQ_Parent_Name"/> > </property> > <property name="Active" access="property" type="Boolean"> > <column name="Active" not-null="true"/> > </property> > <property name="ListOrder" access="property" type="Int32"> > <column name="ListOrder" not-null="true"/> > </property> > <property name="Name" access="property" type="String"> > <column name="Name" not-null="true" unique-key="UQ_Parent_Name"/> > </property> > <property name="Description" access="property" type="String"> > <column name="Description" not-null="true"/> > </property> > <property name="ActivationStartDate" access="property" > type="System.DateTime"> > <column name="ActivationStartDate" not-null="true"/> > </property> > <property name="ActivationEndDate" access="property" > type="System.DateTime"> > <column name="ActivationEndDate" not-null="true"/> > </property> > <property name="Created" access="property" type="System.DateTime"> > <column name="Created" not-null="true"/> > </property> > <property name="Updated" access="property" type="System.DateTime"> > <column name="Updated" not-null="true"/> > </property> > <many-to-one name="Parent" access="property" > class="LMMobileCMS.Server.ServiceLibrary.AbstractServiceObject, > LMMobileCMS.Server.ServiceLibrary" column="ParentId" /> > <joined-subclass name="LMMobileCMS.Server.ServiceLibrary.ContentObject, > LMMobileCMS.Server.ServiceLibrary" table="ServiceContentObject"> > <key column="ContentObjectId" /> > <property name="IContentObjectId" access="property" type="Int32"> > <column name="IContentObjectId" check="IContentObjectId > 0"/> > </property> > </joined-subclass> > <joined-subclass name="LMMobileCMS.Server.ServiceLibrary.Category, > LMMobileCMS.Server.ServiceLibrary" table="ServiceCategory"> > <key column="CategoryId" /> > </joined-subclass> > </class> > </hibernate-mapping> > > But this does not get into the SQL schema generated file > > alter table ServiceObjectBase drop constraint FK5DE21CBB7F9280D > alter table ServiceContentObject drop constraint FKD5E2C4AD59D78DC8 > alter table ServiceCategory drop constraint FKA6B28CE47A768A > if exists (select * from dbo.sysobjects where id = > object_id(N'ServiceObjectBase') and OBJECTPROPERTY(id, N'IsUserTable') = 1) > drop table ServiceObjectBase > if exists (select * from dbo.sysobjects where id = > object_id(N'ServiceContentObject') and OBJECTPROPERTY(id, N'IsUserTable') = > 1) drop table ServiceContentObject > if exists (select * from dbo.sysobjects where id = > object_id(N'ServiceCategory') and OBJECTPROPERTY(id, N'IsUserTable') = 1) > drop table ServiceCategory > create table ServiceObjectBase ( > Id INT IDENTITY NOT NULL, > ParentId INT null, > Active BIT not null, > ListOrder INT not null, > Name NVARCHAR(255) not null, > Description NVARCHAR(255) not null, > ActivationStartDate DATETIME not null, > ActivationEndDate DATETIME not null, > Created DATETIME not null, > Updated DATETIME not null, > primary key (Id), > unique (ParentId, Name) > ) > create table ServiceContentObject ( > ContentObjectId INT not null, > IContentObjectId INT null, > primary key (ContentObjectId) > ) > create table ServiceCategory ( > CategoryId INT not null, > primary key (CategoryId) > ) > alter table ServiceObjectBase add constraint FK5DE21CBB7F9280D foreign key > (ParentId) references ServiceObjectBase > alter table ServiceContentObject add constraint FKD5E2C4AD59D78DC8 foreign > key (ContentObjectId) references ServiceObjectBase > alter table ServiceCategory add constraint FKA6B28CE47A768A foreign key > (CategoryId) references ServiceObjectBase > > 2009/3/3 mausch <[email protected]> > > > > > Can you see if the check is being written to the hbm.xml ? > > > On Mar 2, 10:09 am, Juan Fernandez <[email protected]> wrote: > > > Hi > > > > I've been trying to add a check constraint to a property, but that > > > doesn't get generated on the SQL creation scripts nor in the database. > > > I'm using a code like this one > > > > [ActiveRecord] > > > public class A : ActiveRecordBase { > > > > [Property (Check = "Name <> 'a' ")] > > > public string Name { get; set; } > > > > } > > > > Is there a way to do it? > > > > Thanks !!! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Castle Project Users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en -~----------~----~----~----~------~----~------~--~---
