Anders Hattestad
May 16, 2011
  3119
(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
Opti ID overview

Opti ID allows you to log in once and switch between Optimizely products using Okta, Entra ID, or a local account. You can also manage all your use...

K Khan | Jul 26, 2024

Getting Started with Optimizely SaaS using Next.js Starter App - Extend a component - Part 3

This is the final part of our Optimizely SaaS CMS proof-of-concept (POC) blog series. In this post, we'll dive into extending a component within th...

Raghavendra Murthy | Jul 23, 2024 | Syndicated blog

Optimizely Graph – Faceting with Geta Categories

Overview As Optimizely Graph (and Content Cloud SaaS) makes its global debut, it is known that there are going to be some bugs and quirks. One of t...

Eric Markson | Jul 22, 2024 | Syndicated blog

Integration Bynder (DAM) with Optimizely

Bynder is a comprehensive digital asset management (DAM) platform that enables businesses to efficiently manage, store, organize, and share their...

Sanjay Kumar | Jul 22, 2024

Frontend Hosting for SaaS CMS Solutions

Introduction Now that CMS SaaS Core has gone into general availability, it is a good time to start discussing where to host the head. SaaS Core is...

Minesh Shah (Netcel) | Jul 20, 2024

Optimizely London Dev Meetup 11th July 2024

On 11th July 2024 in London Niteco and Netcel along with Optimizely ran the London Developer meetup. There was an great agenda of talks that we put...

Scott Reed | Jul 19, 2024