Try our conversational search powered by Generative AI!

Anders Hattestad
May 16, 2011
  3095
(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
Azure AI Language – Extractive Summarisation in Optimizely CMS

In this article, I demonstrate how extractive summarisation, provided by the Azure AI Language platform, can be leveraged to produce a set of summa...

Anil Patel | Apr 26, 2024 | Syndicated blog

Optimizely Unit Testing Using CmsContentScaffolding Package

Introduction Unit tests shouldn't be created just for business logic, but also for the content and rules defined for content creation (available...

MilosR | Apr 26, 2024

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