Skip to content

Instantly share code, notes, and snippets.

@greggnakamura
Last active October 4, 2018 20:14
Show Gist options
  • Save greggnakamura/7bd729aa6e3889cc2b354bafcc12f65c to your computer and use it in GitHub Desktop.
Save greggnakamura/7bd729aa6e3889cc2b354bafcc12f65c to your computer and use it in GitHub Desktop.
Kentico: Custom Table `ItemKeyName` set to non-Primary key
/* default */
form.ItemID = QueryHelper.GetInteger(ItemKeyName, 0);
/* by `ItemGUID` */
var ItemKeyNameID = QueryHelper.GetGuid(ItemKeyName, Guid.Empty);
/* option 1: get `ItemID` by custom table generated code */
/* saved code will be placed in /App_Code/CMSClasses */
form.ItemID = CMS.CustomTables.CustomTableItemProvider
.GetItems<SubscribeToContentAlertItem>()
.WhereEquals(ItemKeyName, ItemKeyNameID)
.Column("ItemID")
.FirstObject?.ItemID ?? 0;
/* option 2: get `ItemID` by custom table W/O generated code */
form.ItemID = CMS.CustomTables.CustomTableItemProvider
.GetItems(customTable.ClassName)
.WhereEquals(ItemKeyName, ItemKeyNameID)
.Column("ItemID").FirstObject?.ItemID ?? 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment