I know LINQ is supposed to automatically return strongly typed result sets. When I attach an ObjectDataSource to a LINQ based method however (with no explicit return type), I don’t get access to any of the columns defined in the LINQ.
Example method:
<System.ComponentModel.DataObjectMethod(ComponentModel.DataObjectMethodType.Select)> _
Public Function GetMarketClusterList() As IEnumerable(Of MarketCluster)
Return From d In db.tblMarkets
Select New MarketCluster With {.MarketCluster = d.MarketCluster}
Distinct
End Function
Public Class MarketCluster
Public MarketCluster As String
End Class
EDIT
I changed my code to use an explicit type and select into that. At least now I know the return type, but it doesn’t help with the original problem. Even weirder, I found with the debugger that if I do
<%# Eval(“MarketCluser”) %> it fails and says “A field or property with the name MarketCluster was not found on the selected data source”, but if I do <% Container.DataItem.MarketCluser %> it works fine!
The error message said the exact error, I just missed it. When it said could not find a “property”, it meant class member called “Property”. I changed my code to this and now it works perfectly.