Constraint on multiple keys

1 view
Skip to first unread message

TrentCioran

unread,
Jun 26, 2009, 7:25:44 PM6/26/09
to Castle Project Users
Hi,

Is there a form to specify a multi-property constraint?

I'd tried with the same value in UniqueKey for two properties but
don't work, say i have the next object

public class MyEntity
{

[Property(UniqueKey="MY_KEY", Unique=true)]
public string PropertyA { get; set; }

[Property(UniqueKey="MY_KEY", Unique=true)]
public string PropertyB { get; set; }

.... more properties

}

but it trhows an exception when i'd tried to save an object, say i
have [new MyEntity { PropertyA = "aValue", PropertyB =
"anotherValue" } ] this saves fine, but if i try to save [new
MyEntity { PropertyA = "aValue", PropertyB = "okAnother" } ] it throws
an exception argumenting that the value already exist (PropertyA =
"aValue").

Can someone help me with this?

Thanks

P.S. sorry for my english =P

DaveG

unread,
Jun 30, 2009, 7:56:47 AM6/30/09
to Castle Project Users
Hi,

On your property definitions you have both UniqueKey and Unique
constraints. This means that in addition to the multi-property
constraint on the combined value that you want you also have a
separate unique constraint on each individual column, and is is this
that is throwing the exception on your first column.

What you want is

[Property(UniqueKey="MY_KEY")]
public string PropertyA { get; set; }


[Property(UniqueKey="MY_KEY")]
public string PropertyB { get; set; }


Dave.
Reply all
Reply to author
Forward
0 new messages