How can I filter using Fields mapped on a related entity

Posts   
 
    
KastroNYC
User
Posts: 96
Joined: 23-Jan-2006
# Posted on: 25-Aug-2006 22:18:33   

I have two Entities like this:

Note

RegardsPersonId Description DateTime

Person

PersonId Name Telephone

In the Entity editor on the Fields mapped on related entity page I added a PersonName field to the Note entity using the Relation Note.RegardsPersonId = Person.PersonId. Now I want to create a predicate expression like:


Protected Sub LLBLGenProDataSource1_PerformSelect(ByVal sender As Object, ByVal e As SD.LLBLGen.Pro.ORMSupportClasses.PerformSelectEventArgs) Handles LLBLGenProDataSource1.PerformSelect

Dim notes As NoteCollection = CType(e.ContainedCollection, NoteCollection)
Dim filter As PredicateExpression = e.Filter

filter.Add(New FieldLikePredicate(HelperClasses.NoteFields.PersonName = something & "%"))

notes.GetMulti(filter)

But i get an error that PersonName is not a member of NoteFields. But if I instantiate a Note it has a Note.PersonName field.. so what gives?

Any help is greatly appreciated. Thanks

-Kas

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 26-Aug-2006 02:51:24   

PersonName is a property that exists only in the code. When generating a query that will run against the database you must still define the relationship from Note to Person and filter on the Name in the Person table.

NoteFields only contains fields that exist in the database, which it why PersonName doesn't exist.

KastroNYC
User
Posts: 96
Joined: 23-Jan-2006
# Posted on: 26-Aug-2006 05:15:12   

Can I have an example of that?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 26-Aug-2006 10:59:15   

You should filter on PersonFields.Name and add the relation between Note and Person as well. You can't filter on PersonName in Note, as Brian says. It might be a bit confusing, but the field 'PersonName' isn't part of the entity Note, it's part of the entity Person, and a shortcut has been given to you in the form of Field mapped onto related field to access PersonName through the Note object, so it is for example easier in databinding.

Frans Bouma | Lead developer LLBLGen Pro
KastroNYC
User
Posts: 96
Joined: 23-Jan-2006
# Posted on: 26-Aug-2006 21:41:09   

I guess my question then is how do I add a relation between the entities? Sorry if its a dumb question but a quick example would be extremely helpful. Thanks.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 26-Aug-2006 22:50:44   

KastroNYC wrote:

I guess my question then is how do I add a relation between the entities? Sorry if its a dumb question but a quick example would be extremely helpful. Thanks.

Instead of filtering on Note.PersonName, you filter on Person.Name and add NoteEntity.Relations.PersonEntityUsingPersonId (or whatever it's called) to the RelationCollection you're passing to the fetch method simple_smile

Frans Bouma | Lead developer LLBLGen Pro