【问题标题】:linq to entities how to create databaselinq to entity 如何创建数据库
【发布时间】:2010-12-15 22:15:55
【问题描述】:

我是 linq to entity 的新手。

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

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

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

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

【问题讨论】:

    标签: c# asp.net entity-framework linq-to-entities


    【解决方案1】:

    试试这个

    // 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();
    

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

    【讨论】:

      【解决方案2】:

      看看 ModelBuilder 类,有一个可以调用的 CreateModel 方法。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多