Collection Data

Posts   
 
    
hommels
User
Posts: 23
Joined: 01-Jul-2005
# Posted on: 22-Jul-2005 21:10:18   

How do you get Pid value from _PersonCollection?

What I have throws an error.

// Get the preferences from the AppUserPreferences table IRelationPredicateBucket filter = new RelationPredicateBucket(); filter.PredicateExpression.Add( PredicateFactory.CompareValue( PersonFieldIndex.Pid, ComparisonOperator.Equal, u.Pid ) ); adapter.FetchEntityCollection(_PersonCollection, filter);

if(_PersonCollection.Count == 0) { throw new ApplicationException( "Pid is not valid for currently logged on user"); } else if(_PersonCollection.Count > 1) { throw new ApplicationException( "Pid returned more than one value for currently logged on user"); } else { //Result only returned 1 FromId = Convert.ToInt32(_PersonCollection.Items[0]); }

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 22-Jul-2005 22:36:32   

Hommels, please consider that we're not able to peek over your shoulder at your code, so please help us with every information you can provide simple_smile like: what kind of error? compiler error, runtime error? at which line? what's 'u' ?

Frans Bouma | Lead developer LLBLGen Pro
alexdresko
User
Posts: 336
Joined: 08-Jun-2004
# Posted on: 22-Jul-2005 22:48:59   

hommels wrote:

else if(_PersonCollection.Count > 1) { throw new ApplicationException( "Pid returned more than one value for currently logged on user"); }

This is most likely unrelated to your problem, but you probably wouldn't have to check for Count > 1 if you put a unique constraint in your Person able. You'll have to check for an ORMQueryException when you add new records to the Person table, but this is better than allowing bad data into your tables.