Collections and Entities

Posts   
 
    
jaxon
User
Posts: 20
Joined: 21-Sep-2005
# Posted on: 11-Oct-2005 17:38:15   

Hello everyone,

I'm having a bit of a problem. I am trying to fetch an entity by the value of a non primary key value. say user name, not user id, I can't fetch by primary key, so I tried fetching a collection, the problem is there will always be only one record returned so returning a collection is not really necessary. I tried using the predicate factory , which works but then i don't know how to use the individual entities in that collection.... here I'll just show you what I've tried

    myUserList.GetMulti(Nothing)

    Dim myUser As UserEntity = myUserList(myUserList.Find(New EntityPropertyDescriptor(EntityFieldFactory.Create(UserFieldIndex.UserName), GetType(UserEntity)), "Bill"))

And I just want to do something like this

dim myUser as new UserEntity myUser.FetchByUserName("Bill")

is this possible? Thanks for the help!!

Drewes
User
Posts: 67
Joined: 18-Aug-2003
# Posted on: 12-Oct-2005 03:23:41   

What you could do is create a Unique constraint on that column, since there always is oly one that should be possible. Then you can use code like that described in the "Using a unique constraint's value" section.