How to check for duplicates on current business object


Author
Message
Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (866 reputation)Advanced StrataFrame User (866 reputation)Advanced StrataFrame User (866 reputation)Advanced StrataFrame User (866 reputation)Advanced StrataFrame User (866 reputation)Advanced StrataFrame User (866 reputation)Advanced StrataFrame User (866 reputation)Advanced StrataFrame User (866 reputation)Advanced StrataFrame User (866 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
I am using a BO with multiple rows taken from the Database Table and want to ensure that I do not have any duplicates (On the BO) before I save.

If I was doing this against the database Table, I would issue someting like:

Select Country , Count(Country) as MyCount from MyTable Group by Country                 and then Test that myCount was not greater than 1

Is there any similar construct I can use for Business Object   i.e. be able to search through the BO and let it throw up any duplicates.
Replies
Ivan George Borges
Ivan George Borges
Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)
Group: StrataFrame MVPs
Posts: 1.9K, Visits: 21K
OK Gerard. Sorry, I thought you wanted a BO free of the duplicates. In fact you want the ones that are duplicates.

There might be easier ways to do it, but I would iterate through your BO and check each row if there is any other with the same content. Everytime I found one, I would store it in some kind of array, collection or even another instance of the same BO.

To look for duplicates, you can use the BO.CurrentDataTable.Select function, as in:

MyBO.CurrentDataTable.Select("MyColumnName = " & MyColumnCurrentValue & " AND MyPrimaryKeyColumnName <> " & MyCurrentPrimaryKeyValue).Length

If this line returned anything greater than 0 this would tell you this row had a duplicate and you could add it to your DuplicatesBO to show the user once finished.
Edited 14 Years Ago by Ivan George Borges
Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (866 reputation)Advanced StrataFrame User (866 reputation)Advanced StrataFrame User (866 reputation)Advanced StrataFrame User (866 reputation)Advanced StrataFrame User (866 reputation)Advanced StrataFrame User (866 reputation)Advanced StrataFrame User (866 reputation)Advanced StrataFrame User (866 reputation)Advanced StrataFrame User (866 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
Hi Ivan.

I have just started to play around with Linq statements (from a Datatable) and it appears to be quite easy to 'Group By' using the Inernal Table from the BO. In that Linq stuff only came  in in .Net 3.5 , would you anticipate any problems using this with SF (I had any projects running on Net 2) . I have changed the Project to 3.5 and have not noticed any problems yet. I would imagine that a Linq group By Statement might be faster than itrating through each BO and doing a search for a duplicate on each row. The particular maintanance forms that I want to validate could have thousands of rows so speed will be a factor
Ivan George Borges
Ivan George Borges
Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)
Group: StrataFrame MVPs
Posts: 1.9K, Visits: 21K
Sorry, but I am affraid I have no expertise on the subject to give you a more accurate answer.

Maybe someone else will chime in and help you with that. You could also run a test on different approaches and decide which goes better for your conditions.
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Gerard,

I compiled all my SF application with .Net 4 runtimes, it is much better, faster and reliable than 2.0, also there are new functionality in version 4 that does not exist in the previous one, so you can go ahead and use 3.5 or better yet 4.

I had used Linq briefly in one of my applications and yes it is very nice and will get you the results you are looking for, so go ahead and use it without hesitation.

Edhy Rijo

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search