从Method返回一个DataSet

时间:2012-01-10 19:16:03

标签: c# linq dataset

我的查询中有一个方法。我的查询是一个LINQs查询,但我希望该方法返回一个DataSet。这是可能的,如果是这样你怎么设置它。

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"],

    });
}

谢谢!

1 个答案:

答案 0 :(得分:3)

这可能有所帮助:Creating a DataTable From a Query