A
A
Alexsbr2019-10-10 21:31:34
C++ / C#
Alexsbr, 2019-10-10 21:31:34

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:
5d9f780a1326e713442801.png
5d9f7814eb15a817987621.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Gennady Kruglov, 2019-10-11
@robinzonejob

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 question

Ask a Question

731 491 924 answers to any question