Developer's Guide - EPiServer World
Developer's Guide - EPiServer World
Developer's Guide - EPiServer World
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
130 | Developer’s <strong>Guide</strong> <strong>EPiServer</strong> Community 3.1<br />
// updating the data<br />
public static void UpdateMyClass(MyClass mc)<br />
{<br />
bool inTransaction = DatabaseHandler.InTransaction;<br />
if (!inTransaction)<br />
DatabaseHandler.BeginTransaction();<br />
try<br />
{<br />
DatabaseHandler.<br />
ExecuteNonQuery(true, "spUpdateMyClass", parameters));<br />
base.UpdateEntity(mc);<br />
if (!inTransaction)<br />
DatabaseHandler.Commit();<br />
}<br />
catch (Exception)<br />
{<br />
if (!inTransaction)<br />
DatabaseHandler.Rollback();<br />
throw;<br />
}<br />
}<br />
}<br />
UpdateEntity saves all categories, tags, attributes and rating settings on MyClass. UpdateEntity has two overloads, during<br />
an insert we call the overload where we can pass the new id, since it’s not in our object at the moment, and when we<br />
do an update, we simply only pass the “mc” variable. This is important to remember, since when passing an ID some<br />
initialization may occur which is unnecessary during an update, so keep track of which overload you call.<br />
3.2.1 Retrieving categories for MyClass<br />
To get a collection of all categories connected to an entity, you just call the Categories property on the categorizable<br />
entity MyClass just as for any <strong>EPiServer</strong> Community object.<br />
//Get the MyClass to check for categories<br />
MyClass myClass = MyClassHandler.GetMyClass(1);<br />
//Get the categories for the blog<br />
CategoryCollection categoryCollection = myClass.Categories;<br />
© <strong>EPiServer</strong> AB