As we are starting a new project I am wondering what your take is on how to create/design the database.
Options:
Use TOAD for SQl Server to create the entities and generate DDL (SQL) script
Use Entity Framework Code First approach where you start with the code
...
My problem with EF code first is that it is hard for me to keep track of changes and actually applying the EF generated migration scripts to the database. Especially in the beginning where changes are anything but rare.
How do you keep track and apply changes to the model? In other words, how do you keep your EF C# code in sync with the database?
Related
I have been asked to write a web site that will use an existing SQL Server database. The database was designed to work with another application, and so I can't make any potentially breaking changes to it.
Unfortunately, the database does not contain a single relational link, each table is standalone.
I know you can use EF commands to scaffold a database and create entity classes, but I would like the code to know the relationships that should exist between the tables.
I thought about scaffolding the database, then modifying the created classes to include the links, but I'm not sure if that would allow EF to load related entities. Also, as I will need to add some new tables to the database, I'm worried that EF will try and create those links when I do the migration.
Is there any way to do this?
My team has inherited a database application that contains hundreds of tables. The application uses Entity Framework and takes a database first approach for development. Our current process is to pull a table or two at a time into the edmx using the Update Model From Database... tool.
We are considering making a new API with .Net Core, but as far as I can tell from the research I have done, there is no equivalent process in the Entity Framework Core tools. The closest thing I can find is to reverse engineer the entire database with Scaffold-DbContext, and then use migrations for all future database changes. We can't scaffold the entire database, because some of the tables have errors, and fixing all those errors is not a viable option for us right now.
I have found that I can supply a list of tables that I want scaffolded with the initial Scaffold-DbContext call, but I'm not sure if migrations can be used in a similar way to the Update Model From Database... tool. Can I use migrations to add tables that already exist in our database? If not, what other options should I be looking at?
I am having an issue with my website(ASP.NET, c#, SQL, Code-first Entity Framework).
I have a project with an attached SQL database generated from code first entity framework.
Now I have imported another SQL database using model first database which looks almost same but the table and column names are different.
So now I would like to write data to two databases at the same time with just one click from my web application.
The newly attached database will be a backup and we should write data to both databases at the same time.
Any suggestions would be highly appreciated.
Thanks
As others have suggested, you need to do the mapping yourself, but one thing I would like to add, you may need to wrap your SaveChanges() into a transaction, you may find steps here: https://msdn.microsoft.com/en-us/data/dn456843.aspx
I'm working on an ASP.NET project. I migrated my database named "youbay" with
reverse engineering. It worked. My database contains tables (picture, user, product...) but when I try to change something on the code and then update my database it with code first other tables are then created named youbay.picture,youbay.user...
What do you concretely mean with RE? Creating ASP.NET Models by guessing the mapped .NET types of the table scheme? Maybe your db-structures are a bit different from the ones EF would genereate itself, so that EF will see a conflict. Or EF keep track of the changes itself, so he isn't touching the tables because he won't recognize that he created them.
Whatever happened, it seems like your way of migrating was not very clean. You should tell EF use an existing database like explained here. This will prevent conflicts and also save work/time, because EF will automatically generate your models based of the database-scheme. So no RE is needed.
I am using NHibernate and Fluent NHibernate for the first time. I had to physically create the database and write SQL scripts for the first 2 tables. Now, i am wondering if this technology (NHibernate), like Entity Framework (Code First) when you have enabled migrations has a similar too to create and update tables?
This is what i mean by Ef Code First Automatic Migrations
nHibernate does support schema changes using SchemaUpdate
See: Is NHibernate SchemaUpdate safe in production code?
You can also generate a create script to execute against your database using nHibernate SchemaExport.
SchemaUpdate is not recommended for production use because of the security privileges that have to be granted in order for this to work. Personally I think you should look at a code based migrations tool which are designed to handle initial database creates plus full revision control, I use Migrator.NET - Database migration in C#