Relative Content

Tag Archive for postgresqlentity-framework

Seeding data in Entity Framework

Im using Entity framework to manage a postgresql database, which has three tables–Products, ProductCategories and ProductImages, these three tables are related to each other through foreign key,for example the ‘ProductCategoryId” of Products table is a foreign key to the “ProductCategories” table, so do the “ProductImageId” which is a foreigh key to the “ProductImages” table.
Here is the data seeding class

Primary Key Value conflict in Entity Framework

Im using Entity framework to mapping a postgres database which has three tables–Products,ProductCategories and ProductImages. If I have a blank database, when I insert a new record, I can see the primary key ‘Id’ started from ‘0’ in three tables, however after seeding a few of records (in my case 30 records) in the tables, then when I try to insert a new record to the database, I receive an error message saying Key value conflict…etc. I guess it’s because it still tries to start with a key value which is conflict to the dummy records in the database? if it’s the case is there any workaround like set the Primary Key’ Id’ started at 31? thanks.