Does anyone have an example of how to create a table using npoco?
I read this blog post about peta poco and Umbraco 7, and i dont know how to write this part in Umbraco 8 and NPoco:
namespace MyWebsite
{
public class RegisterEvents : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
//Get the Umbraco Database context
var db = applicationContext.DatabaseContext.Database;
if (!db.TableExist("BlogComments"))
{
db.CreateTable<BlogComment>(false);
}
Document.BeforePublish += Document_BeforePublish;
}
private void Document_BeforePublish(Document sender, PublishEventArgs e)
{
Log.Add(LogTypes.Debug, sender.Id, "the document " + sender.Text + " is about to be published");
e.Cancel = true;
}
}
}
There's a great resource in this github repository about 'how to do stuff with Umbraco' written by Umbraco legend Kevin Jump, which are mainly his notes for remembering how to do things when he creates his packages and site implementations...
Create table with NPoco
Does anyone have an example of how to create a table using npoco? I read this blog post about peta poco and Umbraco 7, and i dont know how to write this part in Umbraco 8 and NPoco:
Hi Josip
There's a great resource in this github repository about 'how to do stuff with Umbraco' written by Umbraco legend Kevin Jump, which are mainly his notes for remembering how to do things when he creates his packages and site implementations...
https://github.com/KevinJump/DoStuffWithUmbraco
... I mention it because he has an example for V8 of how to create a database table using NPoco
https://github.com/KevinJump/DoStuffWithUmbraco/blob/master/Src/DoStuff.Core/Migrations/CreateTable/CreateTableMigration.cs
inside 'a migration'
Migrations run once so are ideal for creating things like tables...
Also there is an example here in the docs:
https://our.umbraco.com/Documentation/Extending/Database/
regards
Marc
Hello Marc,
Thank you for this valuable informations, I spent 2 days looking for something like that :)
I tried to copy - paste example from Umbraco docs and I am getting red underline from intellisense :
Is that mistake, should it be called
BlogCommentSchema
?BR
Josip
Hi Josip
I reckon you are correct!
as that does appear to be the class which defines the table.
does it work as expected when you use BlogCommentSchema ?
if so, it would be ace if you could edit the documentation page, and create a PR to the repo to correct it.
regards
marc
Yes it creates the table when i change to "BlogCommentSchema".
Sure i will :)
P.S. i have small problems when i want to insert data to the table, but I created another topic for that here
BR
Josip
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.