开发者

Is Entity Framework Code First suited for this scenario?

开发者 https://www.devze.com 2023-04-12 00:24 出处:网络
I have some basic knowledge of Entity Framework 4.1 Code First, but haven\'t used this in a production application yet. I am in the architecture phase of a web app and have made no firm commitments to

I have some basic knowledge of Entity Framework 4.1 Code First, but haven't used this in a production application yet. I am in the architecture phase of a web app and have made no firm commitments to a DAL except that Entity Framework will be used. I have not decided which EF approach: Model First, Database First, or Code First. I was wondering how suitable Code First, or the other two, would be for this scenario. Which of the 3 approaches would work best?

Here is the scenario:

  • Developer does not have DBO permissions on the production database server. This means that the developer cannot run their own DDL/DML comm开发者_开发百科ands or scripts directly on the server. Instead, the DBA would have to execute the DDL/DML commands.
  • The model is expected to change over time, even after the database comes into existence. This means that if using Code First, the database would have to be dropped. To my knowledge, there is no way around this with Code First, and there is not out-of-the box means I know of, with the Code First framework, to maintain the data across re-modelings and drops. Would the DB be dropped in the case of Database First or Model First?

It would be great if you have had experience with a similar situation such as mine.


Point 1 could be solvable by: Developer writes script, Developer gives script to DBA, DBA runs script :)

Point 2:

You don't need to drop the database in Code-First. The usual way in production is to switch off the database initializer (they are mainly meant for development phase only anyway):

Database.SetInitializer<MyContext>(null);

This way your application doesn't touch the database schema at runtime. You will get exceptions though if your model doesn't match the database schema anymore. To migrate to a new schema, you would have to change the schema manually or by scripts (give it to the DBA) to match your changes in the model.

For Database-First approach you have to do the same. And for Model-First too, I believe, because the scripts which Model-First creates by default start with dropping the existing database. None approach creates change scripts for you which only update an existing database schema. They always create the schema from scratch.

So, in my opinion the points you mentioned are not a reason to decide in favor or against Code-First.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号