Tuesday, November 06, 2007

SubSonic - Using the Exist() Method using predicates

Here is a simple example on how to use the Exist() method that hangs of the collection entities generated by SubSonic.




for (int i = 0; i < originalentitycollection.Count; i++)
{
Predicate exist = delegate(Model.Person match)
{
if (match.PersonId == originalentitycollection[i].PersonId)
return true;
else return false;
};


if (!distinctpersoncollection.exists(exist))
{

distinctpersoncollection.add(originalentitycollection[i]);
}
}





You can visit MSDN for more information about the predicate delegates:
http://msdn2.microsoft.com/en-us/library/bfcke1bz.aspx

No comments:

Post a Comment