You probably need to enhance your exist command with ID value:
Select Count(1) From SomeTable Where Name=@name And Type=@Type
and ID<> @Id.
I usually also add candidate index (unique index) on two fields
to protect DB as well.
Sergey Barskiy
Principal Consultant
office: 678.405.0687 |
mobile: 404.388.1899
Microsoft Worldwide Partner of the Year | Custom
Development Solutions, Technical Innovation
From: reagan123
[mailto:cslanet@lhotka.net]
Sent: Friday, November 21, 2008 4:10 PM
To: Sergey Barskiy
Subject: [CSLA .NET] Object or Database to handle duplicate check?
Hello,
Here's my most recent scenario. I have an editable root object that
contains the following fields
ID
Name
Description
Rank
Type
The issue is that we have to keep duplicate entries from being entered.
The combination "Name" and "Type" are the keys as defined
by the customer.
What I started doing was implementing an Exists command object that would pass
in the Name and Type to determine if this combination already exists.
The problem is that if I load an existing object from the database and
update the description and rank, it won't let me save the object because it
already exists in the database.
Is this something that would be handled better at the database instead of in my
object or is there a good way to do this.
Thanks!
Copyright (c) Marimer LLC