Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I get all the fields in an item (in Sitecore)?

I'm trying to write a sql query to get all the fields in a given item in Sitecore.

To say I am stuck is putting it mildly.

I'm guessing I have to do some self joining on the fields table, but I'm getting myself in knots.

Anyone have any ideas?

like image 607
Ian G Avatar asked Oct 22 '09 08:10

Ian G


2 Answers

In none of the cases you should ever try to query the Sitecore database yourself. The database changes over time and this would break your code. Rather, use the Item.Fields. This is a collection which contains all the necessary fields. If you want to make sure that all the fields are loaded(really loaded, not lazy loaded), than you can use Item.Fields.ReadAll().

Edit: Also, keep in mind that querying doesn't allow you to construct an Item, so you miss the behavior of default values and do not use the intelligent Sitecore caching at all.

like image 178
Alex de Groot Avatar answered Oct 17 '22 13:10

Alex de Groot


Try to call Sitecore.Context.Item.Fields.ReadAll() before looking up a field.

like image 21
pbering Avatar answered Oct 17 '22 13:10

pbering