linq to entities how to create database

拈花ヽ惹草 提交于 2019-12-13 04:19:01

问题


I'm new to linq to entities.

In linqtosql you could do something like:

datacontext.CreateDatabase() to generate a database from the model in sql.

I'm wanting to do the same thing in linq to entities.

Say I have a class MyEntities which inherits from ObjectContect is there a similiar method?


回答1:


Try this

// Create a builder and configure it 
var builder = new ContextBuilder<MyContext>(); 
…

// Create a context 
var mycontext = builder.Create(sqlConnection);

// Prepare the Context 
if (!myContext.DatabaseExists()) 
   myContext.CreateDatabase();

Reference: http://blogs.msdn.com/b/alexj/archive/2009/08/12/tip-32-how-to-create-a-database-from-ssdl-ef-4-only.aspx




回答2:


Take a look at the ModelBuilder class, there is a CreateModel method you can call on that.



来源:https://stackoverflow.com/questions/4455520/linq-to-entities-how-to-create-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!