Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Anders Hattestad
May 16, 2011
  3094
(0 votes)

Quick tip with DDS and Linq

I have had trouble with a simple Linq statement.

Code Snippet
  1. public static T GetMyRow(PageReference pageRef)
  2. {
  3.     var query = from item in Items where
  4.     item.PageReferenceString == pageRef.CreateReferenceToPublishedPage().ToString()
  5.     select item;

 

It kept throwing errors like

Methods not supported for type System.Object

Even when I rewrote it to

Code Snippet
  1. public static T GetMyRow(PageReference pageRef)
  2. {
  3.     var query = from item in Items where
  4.     item.PageReferenceString == (pageRef.CreateReferenceToPublishedPage().ToString())
  5.     select item;

I got the same error,

But if I make a function that returned a string like this:

Code Snippet
  1. public static string PageRefAsString(PageReference pageRef)
  2. {
  3.     return pageRef.CreateReferenceToPublishedPage().ToString();
  4. }
  5. public static T GetMyRow(PageReference pageRef)
  6. {
  7.     var query = from item in Items
  8.     where item.PageReferenceString == PageRefAsString(pageRef)
  9.     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 Smile. Cause I used some time before I finally got it to work.

May 16, 2011

Comments

smithsson68@gmail.com
smithsson68@gmail.com May 16, 2011 02:32 PM

Hi,

I'll report this as a bug.

Thanks for sharing.

/Paul.

May 27, 2011 01:11 PM

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

Please login to comment.
Latest blogs
Solving the mystery of high memory usage

Sometimes, my work is easy, the problem could be resolved with one look (when I’m lucky enough to look at where it needs to be looked, just like th...

Quan Mai | Apr 22, 2024 | Syndicated blog

Search & Navigation reporting improvements

From version 16.1.0 there are some updates on the statistics pages: Add pagination to search phrase list Allows choosing a custom date range to get...

Phong | Apr 22, 2024

Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog