By Ger Cannoll - 7/25/2011
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.
|
By Ivan George Borges - 7/25/2011
See if this one helps:
http://forum.strataframe.net/FindPost20253.aspx
|
By Michel Levy - 7/25/2011
Hi Gerard,
I use QueryAdataset for that purpose (locally querying data in a BO in T-SQL). You'll find it here http://www.queryadataset.com/
|
By Ger Cannoll - 7/25/2011
Hi Ivan. Thanks for replying.
I have had a look at the thread and the CopydataFrom method but cannot see any option to copy 'Just' duplicated records, or insert a 'Group By' statement. An example of a CopyDataFrom to copy duplicated records only would be very helpful
|
By Ivan George Borges - 7/25/2011
Did you read Paul's post? Or maybe I am misunderstanding what you are looking for.
MyBO.CopyDataFrom(MyOtherBO.CurrentDataTable.DefaultView.ToTable(True, New String() {"DistictColumn-ColumnName"}), MicroFour.StrataFrame.Business.BusinessCloneDataType.ClearAndFillFromCompleteTable)
This should copy only "distinct" rows from MyOtherBO to MyBO, based on the "DistinctColumn-ColumnName".
|
By Ger Cannoll - 7/25/2011
Hi Ivan. I am not seeing this. Maybe an example might clarify.
Say in the BO . I have following:
IRELAND UK USA JAPAN CHINA IRELAND FRANCE BELGIUM CHINA
I want the duplicates in this (So that I can display an error message , as there should not be any duplicates) . So I want returned:-
IRELAND CHINA
(If I was doing this in Sql, I would use a Select Country ,Count(Country) as MyCount from Mytable Group by Country (And anywhere MyCount > 1 are the duplicates)
|
By Ger Cannoll - 7/25/2011
Hi Michel. Thanks for your reply.
This looks like what I want, but I see its another chargeable piece of software (Not that much I admit but all the bits are starting to add up (e.g. Vis Studio, SF,DEVEX Grid, Devex Reports, Excel Creator etc and 3 or 4 other bits and pieces... its starting to get a bit difficult to keep track of them all !!......). I will try to exhaust other possibilities first , and if I make no headway, may have to come back to this.
|
By Ivan George Borges - 7/25/2011
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.
|
By Ger Cannoll - 7/26/2011
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
|
By Ivan George Borges - 7/26/2011
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.
|
By Edhy Rijo - 7/26/2011
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.
|