Error when try to insert value in database with NPoco
I am using this example from Umbraco docs and when i try to save values to the database table i am getting this error:˛
Cannot insert the value NULL into column 'Id', table
'petapoco.dbo.BlogComments'; column does not allow nulls. INSERT
fails. The statement has been terminated.
Also, after table is created and i check it, I can see that primary key and autoincrement option is not set for id field.
And this I how i insert values:
public class Class1 : IUserComposer
{
public void Compose(Composition composition)
{
composition.Components().Append<SubscribeToContentServiceSavingComponent>();
}
public class SubscribeToContentServiceSavingComponent : IComponent
{
public void Initialize()
{
MemberService.Saved += MemberService_Saving;
}
public void Terminate()
{
}
private void MemberService_Saving(IMemberService sender, SaveEventArgs<IMember> e)
{
foreach (IMember member in e.SavedEntities)
{
var blogPostToAdd = new BlogCommentSchema();
blogPostToAdd.BlogPostUmbracoId = member.Id;
blogPostToAdd.Name = member.Name;
blogPostToAdd.Email = member.Name;
blogPostToAdd.Website = member.Name;
blogPostToAdd.Message = member.Name;
using (var scope = Current.ScopeProvider.CreateScope(autoComplete:true))
{
var database = scope.Database;
// use database
scope.Database.Insert<BlogCommentSchema>(blogPostToAdd);
scope.Complete();
}
}
}
}
}
Error when try to insert value in database with NPoco
I am using this example from Umbraco docs and when i try to save values to the database table i am getting this error:˛
Also, after table is created and i check it, I can see that primary key and autoincrement option is not set for
id
field.And this I how i insert values:
Hi,
We have added PrimaryKeyColumn and that has worked to create table with Primary Key. Please can you try and confirm.
Hi Shaishav,
This is the missing part:
You saved me a lot of time, thank you.
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.