RecreateDatabaseIfModelChanges 在 WPF 中可用吗?

发布于 2024-10-28 13:07:26 字数 1328 浏览 3 评论 0原文

我正在尝试实体框架代码优先。我似乎找不到用于 WPF 4.0 中的 RecreateDatabaseIfModelChanges 的程序集/命名空间。这是 ASP.NET 特有的功能吗?如果没有,我应该引用哪个程序集?

这是我的代码:

using System;
using System.Data.Entity;
using System.Windows;
using CodeFirstTester.Models;

namespace CodeFirstTester
{
    public partial class App : Application
    {
        static App()
        {
            // this fails:
            Database.SetInitializer(new RecreateDatabaseIfModelChanges<NerdDinners>());

            // The type or namespace name 'RecreateDatabaseIfModelChanges'
            // could not be found (are you missing a using directive or
            // an assembly reference?)                

            using (var nerdDinners = new NerdDinners())
            {
                var dinner = new Dinner()
                {
                    Title = "Party at Scott's House",
                    EventDate = DateTime.Parse("12/31/2010"),
                    Address = "Building 40",
                    HostedBy = "[email protected]"
                };
                nerdDinners.Dinners.Add(dinner);
                nerdDinners.SaveChanges();
            }
        }
    }
}

I'm trying out Entity Framework Code First. I can't seem to find the assembly/namespace to use for RecreateDatabaseIfModelChanges in WPF 4.0. Is this an ASP.NET-only feature? If not, what assembly should I reference?

Here's my code:

using System;
using System.Data.Entity;
using System.Windows;
using CodeFirstTester.Models;

namespace CodeFirstTester
{
    public partial class App : Application
    {
        static App()
        {
            // this fails:
            Database.SetInitializer(new RecreateDatabaseIfModelChanges<NerdDinners>());

            // The type or namespace name 'RecreateDatabaseIfModelChanges'
            // could not be found (are you missing a using directive or
            // an assembly reference?)                

            using (var nerdDinners = new NerdDinners())
            {
                var dinner = new Dinner()
                {
                    Title = "Party at Scott's House",
                    EventDate = DateTime.Parse("12/31/2010"),
                    Address = "Building 40",
                    HostedBy = "[email protected]"
                };
                nerdDinners.Dinners.Add(dinner);
                nerdDinners.SaveChanges();
            }
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

聆听风音 2024-11-04 13:07:26

初始化程序称为 DropCreateDatabaseIfModelChanges。它可以在 System.Data.Entity 命名空间中的 EntityFramework.dll (EF 4.1) 中找到。

The initializer is called DropCreateDatabaseIfModelChanges. It can be found in EntityFramework.dll (EF 4.1) in System.Data.Entity namespace.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文