简体   繁体   English

如何使用实体框架6数据上下文创建数据库?

[英]How do I create database using entity framework 6 datacontext?

I am trying to understand the code-first approach : http://blog.logiticks.com/an-absolute-beginner-s-tutorial-for-understanding-entity-framework-s-database-first-model-first-and-code-first-approaches/ 我试图理解代码优先的方法: http : //blog.logiticks.com/an-absolute-beginner-s-tutorial-for-understanding-entity-framework-s-database-first-model-first-and -code先方法/

I create the classes, then I don't know where to add the datacontext file? 我创建了类,然后我不知道将datacontext文件添加到哪里? Note that I put my classes in models folder so should i put the context file there too? 请注意,我将我的课程放在models文件夹中,所以我也应该将上下文文件放在那里吗? and how would the project understand where the context file is and create the database from there? 项目将如何理解上下文文件在哪里并从那里创建数据库? I am new to entity framework, any help is appreciated 我是实体框架的新手,感谢您的帮助

In EF database is created automatically, at least using Code First approach. 在EF中,至少使用Code First方法自动创建数据库。 When your application hits the context, EF will check and ensure that DB exists and is compatible with your model(OK, I have simplified this, but overall it is true). 当您的应用程序到达上下文时,EF将检查并确保数据库存在并且与您的模型兼容(好的,我已经简化了这个过程,但是总体来说是正确的)。

As someone in comments suggested, this tutorial doesn't seem like a viable source of knowledge. 正如有评论的人建议的那样,本教程似乎不是可行的知识来源。 I strongly encourage you to read eg this article. 我强烈建议您阅读这篇文章。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用C#-WPF-Entity-Framework Code First应用程序创建数据库备份? - How do I create database backups using C#-WPF-Entity-Framework Code First application? 如何使用Entity Framework 6在运行时创建数据库和表? - How can I create a database and tables at runtime using Entity Framework 6? 如何使用Entity Framework为静态数据建立数据库? - How do I seed a database with static data using Entity Framework? 实体框架如何从数据上下文中分离特定类型的所有对象? - Entity Framework How Do I Detach All Objects Of Specific Type From Datacontext? 每次使用Entity Framework更新数据库时如何创建新迁移 - How do I create a new migration each time I update the database with Entity Framework 如何创建通用的DataContext工厂? - How do I create a generic DataContext factory? 从Entity Framework连接字符串创建DataContext? - Create DataContext from Entity Framework connection string? 如何使用Entity Framework Core 2.0为X实体创建链接的X实体 - How do I create linked X entities for a X entity using Entity Framework Core 2.0 如何在实体框架中创建只读实体? - How do I create a read only entity in the entity framework? 如何在DbContext之外使用Entity Framework之前创建数据库? - How to make Entity Framework create database before using it outside DbContext?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM