web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to do string compare on entity reference?

(0) ShareShare
ReportReport
Posted on by 30

I'm new to CRM Online...

I have an entity containing an attribute with a reference to a string attribute on a different entity.
Now I want to do a string compare in a data select. The problem is the attribute is type of an entityreference and not a string as I would expect.

Sample on what I'm trying to do (in an assembly plugin):

var result = from c in orgContext.CreateQuery<new_myentity>()
                                             where c.new_baseid == ""
                                             select c;
 

Is there an easy way to accomplish this? I've already tried doing another solution (Though I don't like the solution) where I first select the "base" entity and then do a compare like this:

 

 

However that dosen't work either.... Hope you can help me :)

var baseEntity = from b in .... etc.

 

var result = from c in orgContext.CreateQuery<new_myentity>()
                                             where c.new_baseid.Id == baseEntity.GetEnumerator().Current.ToEntityReference().Id
                                             select c;

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Jacob Broberg Profile Picture
    30 on at
    Fixed the problem myself. 
    The syntax was almost correct, however getting the entity ref should be put into a separate line like thi:
     Guid id = ((EntityReference)entity.Attributes["field"]).Id;
    
    
    var result = from c in orgContext.CreateQuery<new_myentity>()
                                                 where c.new_baseid.Id == id
                                                 select c;

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans