Vulnerability in EPiServer.Forms

Try our conversational search powered by Generative AI!

Anders Hattestad
May 16, 2011
  3041
(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
Google Read Aloud Reload Problems

Inclusive web experiences greatly benefit from accessibility features such as Google Read Aloud. This tool, which converts text into speech, enable...

Luc Gosso (MVP) | Dec 4, 2023 | Syndicated blog

Google Read Aloud Reload Problems

Inclusive web experiences greatly benefit from accessibility features such as Google Read Aloud. This tool, which converts text into speech, enable...

Luc Gosso (MVP) | Dec 4, 2023 | Syndicated blog

Import Blobs and Databases to Integration Environments

In this blog, we are going to explore some new extensions to the Deployment API in DXP Cloud Services, specifically the ability to import databases...

Elias Lundmark | Dec 4, 2023

Join the Work Smarter Webinar: Working with the Power of Configured Commerce (B2B) Customer Segmentation December 7th

Join this webinar and learn about customer segmentation – how to best utilize it, how to use personalization to differentiate segmentation and how...

Karen McDougall | Dec 1, 2023