BigJim
BigJim

Reputation: 411

linq to entities how to create database

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?

Upvotes: 0

Views: 1049

Answers (2)

Antony Scott
Antony Scott

Reputation: 21996

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

Upvotes: 0

RPM1984
RPM1984

Reputation: 73123

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

Upvotes: 1

Related Questions