Is it necessary to seed data before anything done with http requests because I ran into a problem where the database got updated with only null values everytime I hit a http post request.
Thanks a lot for this video. But there is a problem i am facing. After creating Extension Method "Seed" and moving auto-generated code in this Seed method, when i try to again run Scaffold command then old manual changes are erased.
Quick question. Affter adding the seed migrations, my migrations folder in the Solution Explorer now looks quite messy. What is the correct procedure for removing the "SeedEmployeesTable" and "AlterSeedEmployeesTable" migrations from the Solution Manager? Thank you for your videos. They really do help a lot
If the migration has already been applied using Update-Database, then the database needs to be reverted first. In this case, run Update-Database -migration InitialMigration This rolls back the database to when InitialMigration was applied. Then you can use Remove-Migration to remove the migrations created after the InitialMigration.
great video...i'm a bit confused, wasn't the seeding process was just a static example? otherwise what is the right process for generic user typed data being saved to the db?
When controller received user typed data, the action in controller will call the method in repository, and then repository will call dbcontext to interact with database and save user typed data
When I try to update the database for the SeedEmployeesTable migration, I get an error: Violation of PRIMARY KEY constraint 'PK_Employees'. Cannot insert duplicate key in object 'dbo.Employees'. The duplicate key value is (1). The statement has been terminated. Someone please help! Edit: I screwed around trying to fix everything but for some reason the migrations weren't being updated to the database properly and I deleted everything from the database and tried to add mary and john by running the website but then they show up as having id's of 4 and 5 instead of starting at 1 and I'm really confused and panicking and I can't edit the ids from the view data window in visual studioooooo
It is possible that you PrimaryKey attribute is set to auto increment. A primarykey cant have duplicates in a column. So every time you delete a row, the SQL server remembers this action and iterates the id key
I guess no one at Microsoft ever had to massage data during an actual migration. Say you decide to split the data in a "Name" column into a "FirstName" and "LastName" column by looking for the last space.
I have this error (The seed entity for entity type 'User' cannot be added because a non-zero value is required for property 'uid'. Consider providing a negative value to avoid collisions with non-seed data). Please help.
One use-case I can think of is, if you want to populate tables that contain data of dropdownlist controls. For example, you might have a dropdownlist that displays list of countries, states, departments in a company etc. If you want to make sure to have all these tables populated, one approach is to use this seeding technique. You can include the code to create the table and populate it with required initial list data in a single migration if you want to. Hope this answers your question.
I found information that this way of adding seed data is nor recommended for adding user data. It works and could be used for essential data that your app will never work without. Here is a thread explaining how to implement seed data. stackoverflow.com/questions/50785009/how-to-seed-an-admin-user-in-ef-core-2-1-0 If anyone disagrees please leave me a comment below explaining why that is. I am leaning myself right now and I need all the information I can find on the topic.
Thanks alot.u r my guru.i learn everything from Ur tutorial. ,God bless u.
Always you inject us with best practices. Thank you.
Simple & clean. Thanks 🤜🤛
I was trying to figure out how to show the data in visual studio like you did 28 secs into it because I forgot. Thank you :)
Smart solution, this way the content is only added once in the database, which could be a problem with other seed solutions.
Great job
Thank you very much
my new employee changes are showing on the EmployeeDB table but not on my web server(Microsoft edge), anyone know why?
How can seed data for multiple tables with the reference key?
Thank u very much sir!
Obviously i was forgetting to add it as a migration.
Thanks so much dear sir!!
u didn't show how u got 2:11 "Dept.IT" . it seems to be ENUM,isn't it?
Yes
Excellent !!!!
Thanks alot!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Is it necessary to seed data before anything done with http requests because I ran into a problem where the database got updated with only null values everytime I hit a http post request.
شكرا كتير ♥
Suppose we are modernizing an app. do we need to seed the entire data? or Is this just works for new Apps only?
What's the point though I don't get it. It's not even a good strategy for testing.
Hello. thanks for your videos. One question please, If the amount of data is large, is there any other efficient way to do data seeding?
Thanks a lot for this video. But there is a problem i am facing. After creating Extension Method "Seed" and moving auto-generated code in this Seed method, when i try to again run Scaffold command then old manual changes are erased.
Great job
but how can i make this code just run on create table or if table empty
i have a problem every i add-migration add rows to database
Quick question. Affter adding the seed migrations, my migrations folder in the Solution Explorer now looks quite messy. What is the correct procedure for removing the "SeedEmployeesTable" and "AlterSeedEmployeesTable" migrations from the Solution Manager?
Thank you for your videos. They really do help a lot
If the migration has already been applied using Update-Database, then the database needs to be reverted first. In this case, run
Update-Database -migration InitialMigration
This rolls back the database to when InitialMigration was applied.
Then you can use Remove-Migration to remove the migrations created after the InitialMigration.
Hi venkat .I m waiting react js with mvc core ..
Hi venkat,
am eagerly waiting for videos regarding Razor in Asp.net core
great video...i'm a bit confused, wasn't the seeding process was just a static example? otherwise what is the right process for generic user typed data being saved to the db?
When controller received user typed data, the action in controller will call the method in repository, and then repository will call dbcontext to interact with database and save user typed data
When I try to update the database for the SeedEmployeesTable migration, I get an error:
Violation of PRIMARY KEY constraint 'PK_Employees'. Cannot insert duplicate key in object 'dbo.Employees'. The duplicate key value is (1).
The statement has been terminated.
Someone please help!
Edit: I screwed around trying to fix everything but for some reason the migrations weren't being updated to the database properly and I deleted everything from the database and tried to add mary and john by running the website but then they show up as having id's of 4 and 5 instead of starting at 1 and I'm really confused and panicking and I can't edit the ids from the view data window in visual studioooooo
It is possible that you PrimaryKey attribute is set to auto increment. A primarykey cant have duplicates in a column. So every time you delete a row, the SQL server remembers this action and iterates the id key
Nice video. Is there any way to use auto increment on the ID rather than entering the value.
Yes, use this data annotation
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
Can you create tutorials how can I use multiple dbcontext for more than 1 database
thank you
Thanks alot
.HasData method has red underline. Please help
I guess no one at Microsoft ever had to massage data during an actual migration. Say you decide to split the data in a "Name" column into a "FirstName" and "LastName" column by looking for the last space.
I have this error (The seed entity for entity type 'User' cannot be added because a non-zero value is required for property 'uid'. Consider providing a negative value to avoid collisions with non-seed data). Please help.
Could you add a video about AutoMapper?
Hello Gaurav - Sure, I will in our upcoming videos. It's a great tool.
Is there a reason why we would ever seed the database this way instead of in the UI?
One use-case I can think of is, if you want to populate tables that contain data of dropdownlist controls. For example, you might have a dropdownlist that displays list of countries, states, departments in a company etc. If you want to make sure to have all these tables populated, one approach is to use this seeding technique. You can include the code to create the table and populate it with required initial list data in a single migration if you want to. Hope this answers your question.
@@Csharp-video-tutorialsBlogspot Oh so something that will never or rarely change, like enums in c#. Thanks!
Thanks
1st view
the prev and next video links at the end of this video are wrong
Hello Honeytrippers - Thank you very much for letting me know. I have now updated with the correct previous and next videos. Cheers!
Entity framework is very confusing, which one is best "EF" or "ADO"
Pls reply
EF
I found information that this way of adding seed data is nor recommended for adding user data. It works and could be used for essential data that your app will never work without. Here is a thread explaining how to implement seed data. stackoverflow.com/questions/50785009/how-to-seed-an-admin-user-in-ef-core-2-1-0
If anyone disagrees please leave me a comment below explaining why that is. I am leaning myself right now and I need all the information I can find on the topic.
How to seed a database with relations?
You haven't showed how to seed related data..