List<Filter> filters;
List<Deal> deals;
using (DealDataContext db = new DealDataContext())
{
开发者_运维百科 XElement xmlTree = XElement.Parse("<Request><ZipCode>92618</ZipCode></Request>");
var result = db.SearchDeals(xmlTree);
filters = result.GetResult<Filter>().ToList();
deals = result.GetResult<Deal>().ToList();
}
return filters, deals;
What is the best way of returning more than one object?
Create a ViewModel look for best practices. Your case -
public class DealViewModel
{
List<Filter> filters{get; set;}
List<Deal> deals{get; set;}
}
Function -
DealViewModel vm= new DeakViewModel();
using (DealDataContext db = new DealDataContext())
{
XElement xmlTree = XElement.Parse("<Request><ZipCode>92618</ZipCode></Request>");
var result = db.SearchDeals(xmlTree);
vm.filters = result.GetResult<Filter>().ToList();
vm.deals = result.GetResult<Deal>().ToList();
return vm;
}
Create a class that wraps both objects up into one. Then return your wrapper object.
public class Wrapper
{
List<Filter> Filters { get; set; }
List<Deal> Deals { get; set; }
}
精彩评论