Hello,
I'm trying to pull out data from 2 tables and compare table1 with ALL of the values in table2. When it finds a match, it adds it position to a LIST. I'm then using the list to remove the entities from the collection. Its appears to be doing something, but all of the values in the collection are then messed up. I've included a simplified comparison table below with letters of the alphabet used to map the values, so you can see the shift pattern.
No of entites in collection before: 232
No of entites after: 228
Its clearly not actually removing the values. You can see below that it has only actually deleted one - entity number 2 (value of C) The other 3 entities (6,11,17) have just been re-shuffled. Worse still, it has now actually not included some of the entites that were in the original collection, that were not flagged for removal :
Entity (before) (after)
0 A A
1 B B
2 C D
3 D E
4 E F
5 F G
6 G I
7 H J
8 I K
9 J L
10 K M
11 L O
12 M P
13 N Q
14 O R
15 P S
16 Q T
17 R V
Here is the code that I'm using to achieve this task:
void LoadData(int ID)
{
//Get List of Collections already added
EntityCollection<ErcHeritageRelatedCollectionEntity> orgsadded = new EntityCollection<ErcHeritageRelatedCollectionEntity>();
// fetch them using a DataAccessAdapter instance
IRelationPredicateBucket filter = new RelationPredicateBucket();
filter.PredicateExpression.Add(ErcHeritageRelatedCollectionFields.ResourceId == ID);
using (DataAccessAdapter adapter = new DataAccessAdapter())
{
adapter.FetchEntityCollection(orgsadded, filter, 0, null);
}
RadListBoxDestination.DataSource = orgsadded;
RadListBoxDestination.DataTextField = "CollectionTitle";
RadListBoxDestination.DataValueField = "UID";
RadListBoxDestination.DataBind();
//Get List of Collections
SortExpression sorter = new SortExpression(ErcHeritageCollectionFields.CollectionTitle | SortOperator.Ascending);
EntityCollection<ErcHeritageCollectionEntity> orgs = new EntityCollection<ErcHeritageCollectionEntity>();
// fetch them using a DataAccessAdapter instance
using (DataAccessAdapter adapter = new DataAccessAdapter())
{
adapter.FetchEntityCollection(orgs, null, 0, sorter);
}
List<int> items = new List<int>();
foreach (IEntity2 entity1 in orgsadded)
{
int i = 0;
int j = 0;
foreach (IEntity2 entity2 in orgs)
{
if (entity1.Fields[i].CurrentValue.ToString() == entity2.Fields[1].CurrentValue.ToString())
{
string _val1 = entity1.Fields[i].CurrentValue.ToString();
string _val2 = entity2.Fields[1].CurrentValue.ToString();
litFeedback.Text += "Match found " + _val1 + " with " + _val2 + "<br />" ;
items.Add(j);
}
j++;
}
i++;
}
foreach (int currValue in items)
{
orgs.RemoveAt(currValue);
}
RadListBoxSource.DataSource = orgs;
RadListBoxSource.DataTextField = "CollectionTitle";
RadListBoxSource.DataValueField = "CollectionID";
RadListBoxSource.DataBind();
}
Any guidance on whats going wrong here would be great. I'm a relative newcomer to LLBLGen pro.
Thanks,
Alan