Answer the question
In order to leave comments, you need to log in
How to insert value into OpenCart(MySql) database using C# and EF6?
Hello! I'm learning OpenCart. And I want to insert a row into the OpenCart database, into the "oc_category" table using C# and EntityFramework. And this is obtained for all fields, except for the category_id field.
Initially it was always =1. I saw that incrementation was enabled and turned it off. However, the situation has not changed.
The null value for this field cannot be set either. it is the primary key. I also set the default value = 0, but all in vain. What am I doing wrong? Is it possible for me to somehow insert a value into this field? or is it basically impossible in MySql?
I insert using this method:
public void SeedCategory(List categories)
{
using (var context = new DbContext())
{
foreach (var item in categories)
{
context.oc_category.Add(item);
Console.WriteLine(item.category_id);
}
context.SaveChanges();
}
}
Base screenshots:
Answer the question
In order to leave comments, you need to log in
Because this field is the primary key -
most likely in the data model, for EF you need to set its StoreGeneratedPattern to identity .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question