Object or Database to handle duplicate check?

Object or Database to handle duplicate check?

Old forum URL: forums.lhotka.net/forums/t/5852.aspx


reagan123 posted on Friday, November 21, 2008

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!

sergeyb replied on Friday, November 21, 2008

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

cid:_2_0648EA840648E85C001BBCB886257279
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!


reagan123 replied on Friday, November 21, 2008

You are the man!!!!

Copyright (c) Marimer LLC