Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Having a go with v8 but noticed that some of the db method have gone private so not sure how to do the following:
//Create DB table - and set overwrite to false
If you use migrations, you could use something like this:
public class InitialMigration : MigrationBase
public InitialMigration(IMigrationContext context) : base(context)
public override void Migrate()
Stephan has write a blog about migrations in V8 - https://www.zpqrtbnk.net/posts/migrations-in-v8
thanks, will give it a go!
I think you need to add .Do() to your Create.Table call.
And you can get the expected table name from NPoco by writing TableInfo.FromPoco(typeof(BlogComment)).TableName
So the Migrate method would be like this:
public override void Migrate()
That is how I got it working :)
Thank you, this code below I used for playing with Umbraco and works. I see that I missed the .Do() in the post above, I will change it.
Thanks for the extra info Søren
And if I don't want to run this from a migration (since it needs to run on every app start), could I also execute that code from a component? https://creativewebspecialist.co.uk/2018/06/15/umbraco-v8-bye-bye-applicationeventhandler-hello-umbraco-components/
Any reason you need to run SQL everytime the app boots?
As everyone has mentioned, using migrations is the way to go for this.
With migrations it will save you this work, if an envionment such as local to development or development to live, has not run a migration (the current latest state of a migration is stored)
So if the Live site does not have migration-c but has migration-a in its DB it will go through migrations migration-b & migration-c
So migrations is the way to deal with SQL/Table stuff.
Look at V8 core and how many migrations we have just for V8.0.0
And take a look at what we do again in V8 core to ensure we go through all the steps/migrations in a specific order
Hope this helps.
But if you need or want to use SQL/NPoco (The PetaPoco replacement) you could use something like this.
Note the scope.complete() without it, the transaction/SQL will not be applied.
using (var scope = Current.ScopeProvider.CreateScope())
var sql = scope.SqlContext.Sql()
.Where<Record>(x => x.UniqueId == recordId);
var formId = scope.Database.ExecuteScalar<Guid>(sql);
Hi Warren, thanks for the details, well I need it to run more then once since I'm building up types on the fly based user input.... , is there a way I can force execute a migration? Or in your second example how would you create a table based on a type?
I would use the Scope approach in that case as you need to do it at runtime it seems so you could then create your new table as needed I assume of some GUI or some user based input/action
THanks, got an example of using the Scope approach and combining it with
Since I don't see any create table stuff on there
Did you ever find a way to create tables without migration?
in this post they replied to me how to make the custom table
It's the same as the suggestions in this thread.
But it still uses Migration. And i wanted to know if it was possible without Migration.
Nope not yet Bo, @Warren any further ideas?
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted