linq到实体如何创建数据库 [英] linq to entities how to create database

查看:92
本文介绍了linq到实体如何创建数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在linqtosql中,您可以执行以下操作:



datacontext.CreateDatabase()从sql中的模型生成数据库。



我想在linq中对实体做同样的事情。

$ b假设我有一个类继承自ObjectContect的类MyEntities是否有类似的方法?

解决方案

尝试这个

  //创建一个构建器并配置它
var builder = new ContextBuilder< MyContext>();
...

//创建上下文
var mycontext = builder.Create(sqlConnection);

//准备上下文
if(!myContext.DatabaseExists())
myContext.CreateDatabase();

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


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?

解决方案

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

这篇关于linq到实体如何创建数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆