问题
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