Can I query two different entities (tables) within a dataservice from within the same Silverlight Project?
I feel like I'm missing a key concept, but after 3 days I need a nudge in the right direction (3 days is my limit for chasing my own tail). My scenario is as follows:
I am trying to add Silverlight datagrids to my existing ASP.NET website. I have 6 or 8 general categories of data that I want to display in silverlight data grids depending on the page the user if viewing. My plan was to pass an initParm to my Silverlight Control to indicate which Class (.xaml page) to load. At this point I have 2 .xaml pages, each with a datagrid and a simple select case in my App.xaml.vb - Application_Startup event. Seems to work just fine with no data (the control loads empty on my .aspx as I expected). When I try to databind the grids is when things got weird. The following is the code from my Page.xaml class showing what I'm trying to do:Private Sub RunQuery() Dim q = From a In dataService.FirstTable _ Order By a.Name _ Select a 'Convert to a DataServiceQuery Dim tbl1Query = CType(q, DataServiceQuery(Of FirstTableType)) 'Start the asynchronous query processing tbl1Query.BeginExecute(AddressOf OnLoadComplete, tbl1Query)
In my OnLoadComplet event, I'm putting my results into an observable collection and binding it to my datagrid. This works just fine on the first page/table. Its when I try to use the same construct on my second page (Page2.xaml let's say) I get an invalid cast exception when I try to cast the Linq to DataServiceQuery. The query is exactly the same (of course the underlying data is different), just a basic select and order by.
I have verified that the data table and data service are okay by creating a seperate Silverlight application in my existing solution, creating a service reference to the same data service I'm using above, and using the same construct in my Page.xaml.vb of that project. What really blew me away was that I can display the results from "FirstTable" in both datagrids and navigate between my 2 .aspx pages in my website and everything seems to work fine. My plan was to factor my queries and data service calls out to a class and just call class methods from my .xaml code-behind files, but I couldn't get that to work at all (even with FirstTable).
It seems like I can't reference 2 different data classes (within the same .edmx) within the same Silverlight application. Can this be true? If I need a separate Silverlight project for each of the 8 grids I need I can do that, but that just doesn't seem right to me. Any suggestions?