Campo de incremento automático personalizado en Umbraco

I have worked with my self programmed CMS but new on Umbraco. I am working on Umbraco 4.7 with .net framework 4 and want to create a content structure somewhat like this

|--------------Model (Can be multiple)
                 |----------- Model Id (Problem) 
                 |----------- Name
                 |----------- DOB
                 |----------- etc...

I need to create node for each Model and want to assign a unique Model Id to each model but can't find any data type that can be used for Auto Increment field (As I do when programming custom .net code with SQL). I know that I can use @pageId, but I want Model Id to start from 100 and with single increment for each Model only.

Necesitas ayuda...

preguntado el 31 de julio de 12 a las 11:07

2 Respuestas

One option is that you could handle the Document.AfterPublish event in a custom library that could add the auto increment value to a "autoID" field after creation and save/publish it again. You may need to keep a counter of the current increment id value (say in the "MaleModels" node above) so you don't have to query all of the Models each time to find the highest ID.

Here's a blog post about events in Umbraco that may help with the details:

Respondido 02 ago 12, 21:08

Thanks for your reply, after some more analysis, I got an idea. Shouldn't I create another table ModelInformation[ModelId PK (AutoIncrement), ModelNodeId (FK from cms_Content)], and as stated by you I can use Umbraco event model to perform this task. Is it the cms_Content table that stores nodeIds of Umbraco nodes. If it is then I can use Umbrao event model to get "created node Id" and store it in ModelInformation table. Next time whenever a Model node is encountered, I'll take its nodeId and find the corresponding ModelId from ModelInformation table. - nishant kumar

Yes, you could certainly add another table and store it that way as well. Would it be important to see that ID in the Umbraco Admin area? You may want to create a simple UserControl DataType that displays the ID on the page in the admin area. - BeaverProj

Yes, it will be good to show model Id in admin area, actually in a label. In fact, I have found a good project on, Do you also have something to share? - nishant kumar

This video is a good tutorial:… - BeaverProj

Tim's blog a nibble is a great resource as well. - BeaverProj

Why don't you create "Custom User Control" which has database and you can create first column as Auto-incremental and second column as NodeId, once you done that please add that into the database on Page_Load() event make sure you check if NodeId exist then don't insert record.

Now create as DataType in Umbraco then use as property, User Control will get Auto-incremental number when you create node that user control will insert record with NodeId and will generate Auto-incremental and display into the page_load() dentro <asp:Label>,

It will heat every time page load so what you can do is that you will need to check every time into you database is NodeId exist or not if it exist then don't insert otherwise insert into the database that way you can create your auto-incremental,

You need to bare in mind that will be heating every-time database just make sure with performance wise you need to look into it.

if you have further question please do let me know.

Muchas Gracias


Respondido 31 Jul 12, 11:07

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.