Page 1 of 1

How to get specified Entity from TMappedCollection

Posted: Thu 06 Jan 2022 18:59
by ajablono
Hi,
i'm newbe in the Entity-World ;-)
how i can get a entity from a collection according to spectial atributes and values ( like TDataSet.Locate () ).
Currently i'm do ot with an loop:
for ASetting in ASettings do
begin
if ASetting.ArticleNumber =5 then
begin
// i found the entity in the collection
Break;
end;

end;

But this is very primitive solution.
Can somebody help me with better solution?
Greetings Andy

Re: How to get specified Entity from TMappedCollection

Posted: Thu 13 Jan 2022 22:47
by MaximG
EntityDAC doesn't have a method similar to TDataSet.Locate. You can implement a similar behavior by retrieving every item from a collection, as shown in the EntityDAC demo ("Get Entities by Collections"). Another way is to find the needed element using a LINQ expression.