Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Linq error Unable to cast object of type 'Microsoft.Xrm.Sdk.Linq.Query`1[EarlyBound.Contact]' to type 'EarlyBound.Contact'

Posted on by Microsoft Employee

I m querying entity. here is my query,

 Contact c1=
                       (Contact)(from c in ppContext.pp_configurationSet
                        join p in ppContext.ContactSet.DefaultIfEmpty()
                        on c.cav_name equals p.FullName
                        where c.pp_name == "DELBY" &&
                        c.StateCode == pp_configurationState.Active
                        select p);


plz guide hot to convert it Entity "Contact". thanks

*This post is locked for comments

  • Suggested answer
    Temmy Wahyu Raharjo Profile Picture
    Temmy Wahyu Raharjo 2,914 on at
    RE: Linq error Unable to cast object of type 'Microsoft.Xrm.Sdk.Linq.Query`1[EarlyBound.Contact]' to type 'EarlyBound.Contact'

    Hi hussmom,
    You need to understand ppContext.pp_configurationSet will return EntityCollection data. So for that code, you need to do something like this:

     Contact c1=
                           (from c in ppContext.pp_configurationSet
                            join p in ppContext.ContactSet.DefaultIfEmpty()
                            on c.cav_name equals p.FullName
                            where c.pp_name == "DELBY" &&
                            c.StateCode == pp_configurationState.Active
                            select p).FirstOrDefault();


    Hope this help!

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans