Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7048873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:56:38+00:00 2026-05-28T02:56:38+00:00

I have a query in a method so I can call i from multiple

  • 0

I have a query in a method so I can call i from multiple places like so:

private object GetData(ProfilePropertyDefinition lProfileProperty)
{   
    return from r in gServiceContext.CreateQuery("opportunity")
           join c in gServiceContext.CreateQuery("contact") on ((EntityReference)r["new_contact"]).Id equals c["contactid"] into opp
           from o in opp.DefaultIfEmpty()
           where ((EntityReference)r["new_channelpartner"]).Id.Equals(lProfileProperty.PropertyValue) && ((OptionSetValue)r["new_leadstatus"]).Equals("100000002")
           select new
           {
               OpportunityId = !r.Contains("opportunityid") ? string.Empty : r["opportunityid"],
               CustomerId = !r.Contains("customerid") ? string.Empty : ((EntityReference)r["customerid"]).Name,
               Priority = !r.Contains("opportunityratingcode") ? string.Empty : r.FormattedValues["opportunityratingcode"],
               ContactName = !r.Contains("new_contact") ? string.Empty : ((EntityReference)r["new_contact"]).Name,
           };
}

Then in another method I call the query method like so and try to loop through it:

var exportData = GetData(lProfileProperty);
foreach (var lItem in exportData)
{
}

Then in the same method when I try to loop through the results I keep getting this error on the foreach:

foreach statement cannot operate on variables of type ‘object’ because ‘object’ does not contain a public definition for ‘GetEnumerator’

Any idea what would cause and how to fix it, I’m stumped.

EDIT:

Took Jon’s advice and for the most part it seems to be working. But when I call the method like: GetData<lProfileProperty.PropertyValue>; It says lProfileProperty can’t be found. But it’s there. Any ideas?

EDIT 2: I have everything from Jon’s example in place. I’m getting one error though: On foreach (GridDataItem lItem in exportData) it is saying Error 67 Cannot convert type ‘DotNetNuke.Modules.CPCLeadShare.View.Foo’ to ‘Telerik.Web.UI.GridDataItem’ any ideas on how to fix this? I need to be able to use the DGridDataItem so I can access the “Cells”.

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:56:39+00:00Added an answer on May 28, 2026 at 2:56 am

    The compiler is telling you what the problem is: you cannot iterate over something that has a static type of object. Fix the return type of your GetData method to return something that implements IEnumerable.

    Since you are returning a sequence of an anonymous type, you could do this simply by changing the code to

    private IEnumerable GetData(ProfilePropertyDefinition lProfileProperty) 
    

    However, you would then be unable to access the properties in the objects except by reflection. To fix that as well, you need to create a new class and return instances of that. For example:

    class Foo {
        public string OpportunityId { get; set; }
        public string CustomerId { get; set; }
        public string Priority { get; set; }
        public string ContactName { get; set; }
    }
    

    and then

    private IEnumerable<Foo> GetData(ProfilePropertyDefinition lProfileProperty) {
       // ...
       select new Foo
           { 
               OpportunityId = !r.Contains("opportunityid") ? string.Empty : r["opportunityid"], 
               CustomerId = !r.Contains("customerid") ? string.Empty : ((EntityReference)r["customerid"]).Name, 
               Priority = !r.Contains("opportunityratingcode") ? string.Empty : r.FormattedValues["opportunityratingcode"], 
               ContactName = !r.Contains("new_contact") ? string.Empty : ((EntityReference)r["new_contact"]).Name, 
           }; 
        // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a xml string that return from Post method: private static void GetResponseCallback(IAsyncResult
If you have a controller method like so: @expose(json) def artists(self, action=view,artist_id=None): artists=session.query(model.Artist).all() return
I have a SqlCommand object, and I execute its ExecuteNonQuery method. The query fails,
So, I have a method that performs a parametrised LIKE query. The method takes
I have a silverlight client that can call a method on my WCF web
I have this method in my db class public function query($queryString) { if (!$this->_connected)
I have a method that basically returns the results of a mysql query. public
Have a lot of unnecessary results using contains() method in my query. Don't tell
I have a method that takes an IQueryable. Is there a LINQ query that
It looks like #temptables created using dynamic SQL via the EXECUTE string method have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.