user482375
user482375

Reputation:

Return a DataSet from Method

I have a method with my query in it. My query is a LINQs query, but I want the method to return a DataSet. Is this possible, if so how you you go about setting that up.

private DataSet ListAllData(string distributorId)
{
     var theQuery =  (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(distributorId) && ((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,
         Source = !r.Contains("new_sourcepick") ? string.Empty : r.FormattedValues["new_sourcepick"],

    });
}

Thanks!

Upvotes: 1

Views: 576

Answers (1)

TheNextman
TheNextman

Reputation: 12566

This may be of help: Creating a DataTable From a Query

Upvotes: 3

Related Questions