I am working with two context classes that are connected to two different databases. But on my index view I need to get info from both databases and then apply the paging to the join result. To do so I define the following viewModel class:-
public class RackJoinList
{
public IEnumerable<TMSRack> Racks { get; set; } // from the first database
public IEnumerable<Resource> Resources { get; set; } //from the second database
}
And the following repository method to populate the ViewMaodel object:-
public RackJoinList AllFindRacks_j(string q,bool forautocomplete=false)
{
RackJoinList rjlist = new RackJoinList();
var racks = from rack in tms.TMSRacks.Where(
a => a.Technology.Tag.ToUpper()
.StartsWith(q.ToUpper()) || (q == null)
)
select rack;
rjlist.Racks = racks.ToList();
var resources = from resource in entities.Resources
join c in rjlist.Racks
on resource.RESOURCEID equals c.Technology.IT360ID
select resource;
rjlist.Resources = resources;
return rjlist;
}
And finally I have the following Action method:-
public ActionResult Index(string searchTerm=null, int page = 1)
{
var racks = repository.AllFindRacks_j(searchTerm)
.OrderBy(a=>a.Technology.Tag).ToPagedList(page, 5) ;
return View(racks);
}
But the above action method will raise an error since I cannot apply order by and Ipagedlist to non-list object. So can anyone advice on how to solve my problem, which mainly is:-
Join context classes from different databases.
Apply the paging to the join results .
Thanks in adbacne for any help.