ContentItem, GetValue method

Posted by Community Admin on 03-Aug-2018 19:30

ContentItem, GetValue method

All Replies

Posted by Community Admin on 21-Feb-2011 00:00

Hey,

I'm looking for a help with this code:

          var manager = ContentManager.GetManager();
          var item = manager.GetContent().Where(t => (string)t.GetValue("PRODUCT KEY") == key).FirstOrDefault();


I took it from here: http://www.sitefinity.com/devnet/forums/sitefinity-4-x/general-discussions/issue-using-indexof-function-in-fluent-api-query.aspx

It seems to me that when there's a space in argument ("PRODUCT KEY") it doesn't work (err: Unexpected token KEY). I can't rename it now, is there any workaround? Square brackets don't work either.

unexpected token: [\"KEY\",<42>,line=1,col=143]\r\nOriginal Query: DEFINE EXTENT extnt FOR Telerik.Sitefinity.GenericContent.Model.ContentItem; SELECT * FROM extnt AS t1  WHERE t1.appName =  $1 AND t1.PRODUCT KEY =  $2"

Thanks in advance!

Posted by Community Admin on 23-Feb-2011 00:00

Hello Vitaly,

It seems that the problem is in t.GetValue("PRODUCT KEY"). As argument you should put the name of the property that you want. In C# you can't have property with white space in it's name, so this is not valid property. Use the real (valid) property name like ProductKey. Also instead of (string)t.GetValue("PRODUCT KEY"), you can use t.GetValue<String>("PRODUCT KEY").

Regards,
Bonny Bonev
the Telerik team

This thread is closed