getting an entity

Posts   
 
    
mafti
User
Posts: 38
Joined: 27-Oct-2004
# Posted on: 22-Nov-2004 15:57:05   

hi,

i want do this

Public Function CheckEntity(ByVal _entity As EntityBase, ByVal _id As Object) As Boolean Dim col As EntityCollectionBase col.EntityFactoryToUse = _entity.EntityFactoryToUse Dim filter As PredicateExpression filter.Add(PredicateFactory.CompareValue(_entity.Fields(0).FieldIndex, ComparisonOperator.Equal, _id)) col.GetMulti(filter, 1, Nothing, Nothing, 0, 0)

    dim fk as object = col(0).Fields(1).CurrentValue 

End Function

but the filter doesn't work. it won't even compile.

basically the function gets an id and some empty entity object. and i want the real entity

is this possible?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 22-Nov-2004 16:31:42   

mafti wrote:

hi, i want do this

Public Function CheckEntity(ByVal _entity As EntityBase, ByVal _id As Object) As Boolean Dim col As EntityCollectionBase col.EntityFactoryToUse = _entity.EntityFactoryToUse Dim filter As PredicateExpression filter.Add(PredicateFactory.CompareValue(_entity.Fields(0).FieldIndex, ComparisonOperator.Equal, _id)) col.GetMulti(filter, 1, Nothing, Nothing, 0, 0)

    dim fk as object = col(0).Fields(1).CurrentValue 
End Function

but the filter doesn't work. it won't even compile.

With compile errors, it's helpful to mention the error here so I can help you better simple_smile

Your code doesn't work because you try to instantiate an abstract class (EntityCollectionBase), which doesn't work of course.

basically the function gets an id and some empty entity object. and i want the real entity

id is the primary key field value?

What you need is also the name (or index) of the field which is the ID. If that's always index 0, you can do: _entity.Fields(0).CurrentValue = _id _entity.Refetch()

Frans Bouma | Lead developer LLBLGen Pro
mafti
User
Posts: 38
Joined: 27-Oct-2004
# Posted on: 22-Nov-2004 16:34:57   

Otis wrote:

id is the primary key field value?

What you need is also the name (or index) of the field which is the ID. If that's always index 0, you can do: _entity.Fields(0).CurrentValue = _id _entity.Refetch()

ok, but then i get the error

The field is marked readonly and cannot be changed.

otherwise it would be brilliant rage

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 22-Nov-2004 17:03:28   

mafti wrote:

Otis wrote:

id is the primary key field value?

What you need is also the name (or index) of the field which is the ID. If that's always index 0, you can do: _entity.Fields(0).CurrentValue = _id _entity.Refetch()

ok, but then i get the error

The field is marked readonly and cannot be changed.

otherwise it would be brilliant rage

Ah, it's an identity field then. Do instead: _entity.SetNewFieldValue(0, _id) _entity.Refetch()

Frans Bouma | Lead developer LLBLGen Pro
mafti
User
Posts: 38
Joined: 27-Oct-2004
# Posted on: 22-Nov-2004 17:34:10   

Otis wrote:

mafti wrote:

Otis wrote:

id is the primary key field value?

What you need is also the name (or index) of the field which is the ID. If that's always index 0, you can do: _entity.Fields(0).CurrentValue = _id _entity.Refetch()

ok, but then i get the error

The field is marked readonly and cannot be changed.

otherwise it would be brilliant rage

Ah, it's an identity field then. Do instead: _entity.SetNewFieldValue(0, _id) _entity.Refetch()

erm, i still get the same message.

i do hope i don't have to change it in the designer. i use the selfservicing-template btw.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 22-Nov-2004 17:45:22   

Sorry, my bad. (mondays)...

_entity.Fields(0).ForcedCurrentValueWrite(_id) _entity.Refetch()

Frans Bouma | Lead developer LLBLGen Pro
mafti
User
Posts: 38
Joined: 27-Oct-2004
# Posted on: 23-Nov-2004 10:10:20   

Otis wrote:

Sorry, my bad. (mondays)...

_entity.Fields(0).ForcedCurrentValueWrite(_id) _entity.Refetch()

thanx simple_smile