views:

37

answers:

0
PK_RPM_BTN_SETTING_ID FK_BUTTON_ID FK_ITEM_OR_PKG       IS_ITEM_OR_PKG SORT_ORDER
--------------------- ------------ -------------------- -------------- ----------
1                     1            1                    I              1
1                     2            1                    P              2
1                     3            1                    I              3
2                     1            1                    P              1
2                     2            1                    I              2
2                     3            1                    I              3

Consider my table above which is sorted on the basis of PK_RPM_BTN_SETTING_ID and SORT_ORDER.

Here Sort Order plays an important role other than displaying data at UI. When Inserting some data I can shorten my search by removing all the recods whereever my search fails. I have a collection containing some buttons with properties

  1. FK_BUTTON_ID
  2. FK_ITEM_OR_PKG
  3. IS_ITEM_OR_PKG
  4. SORT_ORDER = (Index of button in collection + 1)

fields as a property. First of all I will check

               PkgBtnSettingMapper.AsEnumerable().Where(row
                    => (row.Field<short>("SORT_ORDER") == button.SortOrder
                    &&
                    row.Field<int>("FK_BUTTON_ID") == button.PK_Button_ID
                    &&
                    row.Field<long>("FK_ITEM_OR_PKG")==button.ItemOrPkgId
                    &&
                    row.Field<string>("IS_ITEM_OR_PKG") == button.IsItemOrPkg.ToString()
                    )

for first row and if it results in false I will remove all records from the table where PK_RPM_BTN_SETTING_ID is same for remaining records and is not interested for rest of the search.

i.e my first item in the collection {1,1,'I', 2}

PK_RPM_BTN_SETTING_ID FK_BUTTON_ID FK_ITEM_OR_PKG       IS_ITEM_OR_PKG SORT_ORDER
--------------------- ------------ -------------------- -------------- ----------
1                     1            1                    I              1

This record doesn't matches so remove all the records from table permanently where PK_RPM_BTN_SETTING_ID =1 and then continue search for second record i.e.

2                     1            1                    P              1
2                     2            1                    I              2
2                     3            1                    I              3

If it matches store this into some collection and move on to the next record and so on.

After whole scan is complete same process will go on for next button in the collection but for the newly obtained table in the above steps.

This is what I am trying to do but not getting how to implement it.

            PkgBtnSettingMapper= //contains some table data

            DataTable dt = PkgBtnSettingMapper.Clone();
            List<DataRow> drList=new List<DataRow>();
            objRpmButtonHolder.RpmButtonCollection.ForEach(button
                => { 
               PkgBtnSettingMapper.AsEnumerable().Where(row
                    => (row.Field<short>("SORT_ORDER") == button.SortOrder
                    &&
                    row.Field<int>("FK_BUTTON_ID") != button.PK_Button_ID
                    &&
                    row.Field<long>("FK_ITEM_OR_PKG")!=button.ItemOrPkgId
                    &&
                    row.Field<string>("IS_ITEM_OR_PKG") != button.IsItemOrPkg.ToString()
                    )).ToList();//add this list to drList and loop back for next search result
            });