Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Power Apps Pro Dev & ISV
Answered

'The entity with a name = '*****' with namemapping = 'Logical' was not found in the MetadataCache. || Plugin error

(0) ShareShare
ReportReport
Posted on by 559

Hi guys,

 

I have issue i can not seem to resolve myself. I have multiple situations that I need to get N:N data with only the ID of one side of the relationship. 

 

Example: I need to find all Trainees of a Training which is a N:N. I have the Training ID how do i query this?

 

I tried the following:

In this example:

  • cursist = Trainee
  • opleiding = Training

 

if (context.MessageName == "Update" && context.Stage == 20)
 {
 targetEntity = context.InputParameters["Target"] as Entity;

 List<Guid> cursistID = new List<Guid>();
 QueryExpression query = new QueryExpression("cref8_cursist");
 query.ColumnSet = new ColumnSet(new string[] { "cref8_cursistid" });

 LinkEntity linkEntity1 = new LinkEntity("cref8_cursist", "cref8_Opleiding_cref8_Cursist_cref8_Cursi", "cref8_cursistid", "cref8_cursistid", JoinOperator.Inner);
 LinkEntity linkEntity2 = new LinkEntity("cref8_Opleiding_cref8_Cursist_cref8_Cursi", "cref8_opleiding", "cref8_opleidingid", "cref8_opleidingid", JoinOperator.Inner);

 linkEntity1.LinkEntities.Add(linkEntity2);
 query.LinkEntities.Add(linkEntity1);

 linkEntity2.LinkCriteria = new FilterExpression();
 linkEntity2.LinkCriteria.AddCondition(new ConditionExpression("cref8_opleidingid", ConditionOperator.Equal, targetEntity.Id));

 EntityCollection cursistCollection = service.RetrieveMultiple(query);
 if (cursistCollection.Entities.Count > 0)
 {
 foreach (var cursist in cursistCollection.Entities)
 {
 //DO SOME LOGIC
 }
 }

 }

 

 

What's wrong with my code?

Best Regards,

Anthony

  • Steveo32732 Profile Picture
    21 on at
    Re: 'The entity with a name = '*****' with namemapping = 'Logical' was not found in the MetadataCache. || Plugin error

    Awesome explanation... After trying several different ways NOT to do it, this got me exactly what I was after!  Thanks!!

  • Verified answer
    AnthonyD Profile Picture
    559 on at
    Re: 'The entity with a name = '*****' with namemapping = 'Logical' was not found in the MetadataCache. || Plugin error

    @GuidoPreite,

     

    I came to the conclusion that I was querying the N:N relationName and not the entityName. After changing this and working a bit on my code I came with the following working code:

     targetEntity = context.InputParameters["Target"] as Entity;
     var courseID = targetEntity.Id;
     var query = new QueryExpression()
     {
     //Set this to the entity you wish to retrieve data from
     EntityName = "cref8_cursist",
    
     //This will return us all columns for each record returned
     ColumnSet = new ColumnSet(true),
     };
    
     //AddLink(RELATIONSHIP ENTITY NAME, ENTITY UNIQUE ID FROM THE ENTITIE YOU WISH TO RETRIEVE DATA FROM, ENTITY UNIQUE ID FROM THE ENTITIE YOU WISH TO RETRIEVE DATA FROM
     var link = query.AddLink("cref8_opleiding_cref8_cursist", "cref8_cursistid", "cref8_cursistid");
     link.LinkCriteria = new FilterExpression()
     {
     //Add this to filter the Trainee records for a specified Course
     Conditions =
     {
     new ConditionExpression("cref8_opleidingid", ConditionOperator.Equal, courseID)
     }
     };
    
     //Invoke the service with our query
     var subjectEntities = service.RetrieveMultiple(query);
    
     //Loop through the result
     for (var i = 0; i < subjectEntities.Entities.Count; i++)
     {
     //Do some logic
     }

     Best Regards,

    Anthony

  • Guido Preite Profile Picture
    1,488 Super User 2024 Season 1 on at
    Re: 'The entity with a name = '*****' with namemapping = 'Logical' was not found in the MetadataCache. || Plugin error

    Hi,

    in your title you don't specify the exact entity that is triggering the error (if you are getting the asterisks please let me know)

    I can't test your code but probably it has to do with the interest table that you wrote the SchemaName but it should be the logicalName (so all lowercase)

    However I would do a different approach, most of the time (especially with custom tables) you can query directly the intersect entity, so assuming you want to get all the IDs of the cref8_cursist table, I would write something like

    QueryExpression query = new QueryExpression("cref8_opleiding_cref8_cursist_cref8_cursi"); // NOTE: I wrote it lowercase
    query.ColumnSet = new ColumnSet("cref8_opleidingid", "cref8_cursistid");
    query.Criteria.AddCondition("cref8_opleidingid", ConditionOperator.Equal, targetEntity.Id);
    EntityCollection collIntersect = service.RetrieveMultiple(query);
    foreach (Entity intersect in collIntersect.Entities)
    {
    	Guid cursistId = intersect.GetAttributeValue<Guid>("cref8_cursistid"); // inside the intersect table the two columns should be Guid, NOT EntityReference
    	// rest of your code
    }

    hope it helps 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Power Apps Pro Dev & ISV

#1
WarrenBelz Profile Picture

WarrenBelz 87 Most Valuable Professional

#2
mmbr1606 Profile Picture

mmbr1606 71 Super User 2025 Season 1

#3
Michael E. Gernaey Profile Picture

Michael E. Gernaey 65 Super User 2025 Season 1

Overall leaderboard