Quick tip with DDS and Linq
I have had trouble with a simple Linq statement.
- public static T GetMyRow(PageReference pageRef)
- {
- var query = from item in Items where
- item.PageReferenceString == pageRef.CreateReferenceToPublishedPage().ToString()
- select item;
It kept throwing errors like
Methods not supported for type System.Object
Even when I rewrote it to
- public static T GetMyRow(PageReference pageRef)
- {
- var query = from item in Items where
- item.PageReferenceString == (pageRef.CreateReferenceToPublishedPage().ToString())
- select item;
I got the same error,
But if I make a function that returned a string like this:
- public static string PageRefAsString(PageReference pageRef)
- {
- return pageRef.CreateReferenceToPublishedPage().ToString();
- }
- public static T GetMyRow(PageReference pageRef)
- {
- var query = from item in Items
- where item.PageReferenceString == PageRefAsString(pageRef)
- select item;
I didn’t get the error. I guess there are something with what get executed or evaluated first, or something. But if you get this error message: Methods not supported for type System.Object. Maybe this is your problem, and you can save your self some time debugging it . Cause I used some time before I finally got it to work.
Hi,
I'll report this as a bug.
Thanks for sharing.
/Paul.
Currently we're not supporting .ToString() in a LINQ query. It doesn't matter if it's a method or a property. I hope we will support this soon.
/ Jonas