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)

LINQ Query Invalid Where condition Error.

(0) ShareShare
ReportReport
Posted on by

I have a Agent entity having 3 columns AgentGuid (PK), AgentId (not unique) and AgentName. I have a csv file have 2 columns (AgentId, AgentName) which are comma separated to be passed as filter condition.

1001,Agent1

1002,Agent2

1003,Agent3

1001,Agent4

I wrote the LINQ query like below :

var AgentIds = new List<Guid?>();
var filter = File.ReadLines(strFilePath).Select(line => line.Split(','));
AgentIds = (from a in linq.AgentSet
             where filter.Any(f => f[0] == a.AgnetID && f[1] == a.AgentName.ToString())
             select a.AgentGuid).ToList();

I thought I am done... but query is giving me exception, 

Exceptions: System.NotSupportedException, "Invalid 'where' condition. An entity member is invoking an invalid property or method."

may be I am missing something please suggest.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    ashlega Profile Picture
    34,477 on at

    There are limitations in the CRM linq provider.

    I don't think you can use the filter there - linq expression gets translated into a FetchXml expression which is, basically, a static XML, so, the way I understand it, you can't use that kind of conditions (filter.Any). And you probably can't use "ToString" on the attribute either (can type cast though)

    Remove that where, select everything to a list, and, then, run a filter on the list..

  • Community Member Profile Picture
    on at

    Thanks Alex for replying,

    Please suggest the correct way to query, I have removed .ToString() from the attributes as it is not needed there.

  • Suggested answer
    ashlega Profile Picture
    34,477 on at

    Hi,

     the simplest solution would be to load all agent records to a list from CRM, and, then, to filter the list:

    var AgentIds = new List<Guid?>();

    var filter = File.ReadLines(strFilePath).Select(line => line.Split(','));

    AgentIds = (from a in linq.AgentSet

                select a.AgentGuid).ToList();

    <Filter the list here>

    Not sure if there is a more "elegant" solution. There are some examples of the supported CRM linq queries here:

    msdn.microsoft.com/.../gg334593.aspx

  • Suggested answer
    NatrajY Profile Picture
    3,040 on at

    Change

    linq.AgentSet

    to

    linq.AgentSet.AsEnumerable()

    OR use this query instead

    var AgentIds = new List<Guid?>();
    var agentNames = File.ReadLines(strFilePath).Select(line => line.Split(',')).Select(line => new { AgnetID = line[0], AgentName = line[1] });
    AgentIds = (from n in agentNames
    			join a in linq.AgentSet on new { n.AgnetID, n.AgentName } equals new { a.AgnetID, a.AgentName}
    			select a.AgentGuid).ToList();

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