EF 5.0 Enums不生成 [英] EF 5.0 Enums Not Generating

查看:214
本文介绍了EF 5.0 Enums不生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景
我在安装了.Net 4.5的机器上使用VS 2010,我读过的是一个就地安装(覆盖了.net 4.0版本)。



我有仍然针对4.0和4.5选项的项目不可用,但被告知它是确定,因为4.5是一个就地安装。然后,当我运行Upgrade-Database -Script命令时,我通过nuget和通知安装了EntityFramework -pre,它不会生成枚举属性。



然后我发现这个。我尝试从头开始做任何事情,但它仍然添加EntityFramework 4.4而不是5.0。所以我手动更改所有引用到5.0版本,以确保我有EF 5.0版本。全部编译



PROBLEM
当我运行

 启用迁移-EnableAutomaticMigrations 

我得到没有从DbContext派生类在当前项目中
编辑生成的配置类以指定启用迁移的上下文。



所以我手动确保我的类是正确的,如:

 内部密封类配置:DbMigrationsConfiguration< DataContext> 
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
}

DataContext子类DbContext。



当我运行

 更新数据库-Script 

我得到在程序集MyProject中没有找到迁移配置类型(在Visual Studio中,您可以使用Package Manager Console中的Enable-Migrations命令添加迁移配置)



MyProject确实有上面提到的配置类,并且在包管理器控制台中我选择了包含我的项目的正确的下拉列表Migrations文件夹和此配置类。



QUESTION


  1. 当我安装EnittyFramework通过nuget添加5.0版本而不是4.4即使我已经安装了.Net 4.5时,该怎么办?


  2. 如果我无法做任何与上述问题相关的任何事情,我该怎么做才能确保升级数据库会吐出一个脚本?



解决方案

实体框架5.0还没有出来。有 prereleases ,但您需要专门启用prereleases才能使NuGet显示但是,请记住,EF 5.0将不支持.NET 4.0中.NET 4.5中的所有内容。是的,.NET 4.5覆盖.NET 4.0,但是如果您的项目在VS2010中,则它将被配置为构建.NET 4.0,而不是.NET 4.5。它不能假定.NET 4.5功能,因为结果需要在没有.NET 4.5的系统上运行。毕竟,您的目标是.NET 4.0,并且枚举支持不在从NuGet获取的EntityFramework DLL中,它位于.NET运行时的System.Data.Entity DLL中,因此无法添加。 NET 4.0。您可以安装 Visual Studio Beta 来创建目标为.NET 4.5的应用程序。 / p>

简而言之:被告知没有,因为4.5是一个就地安装 - 不,这不符合你的目的。


BACKGROUND I'm using VS 2010 on a machine where I installed .Net 4.5 which I've read was an in-place install (overrode the .net 4.0 version).

I have projects still targeting 4.0 and 4.5 option is not available but was told it's ok since 4.5 was an in-place install. I then installed EntityFramework -pre via nuget and notices when I ran Upgrade-Database -Script commands, it would not generate enum properties.

I then found this. I tried doing everything from scratch again but it was still adding EntityFramework 4.4 instead of 5.0. So I manually changed all references to point to the 5.0 version to make sure I have EF 5.0 version. All compiled.

PROBLEM When I run

Enable-Migrations -EnableAutomaticMigrations

I get "No classes deriving from DbContext found in the current project. Edit the generated Configuration class to specify the context to enable migrations for."

So I manually made sure that my class is correct as in:

internal sealed class Configuration : DbMigrationsConfiguration<DataContext>
{
    public Configuration()
    {
        AutomaticMigrationsEnabled = true;
    }

DataContext subclasses DbContext.

When I run

Update-Database -Script

I get "No migrations configuration type was found in the assembly 'MyProject'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration)."

MyProject does have the configuration class I mentioned above and in Package Manager Console I am choosign the right dropdown for my project containing Migrations folder and this Configuration class.

QUESTION

  1. What do I do to make sure when I install EnittyFramework via nuget that it adds the 5.0 version and not 4.4 even though I have .Net 4.5 installed?

  2. If I can't do anything related to the question above, what can I do to make sure Upgrade-Database spit out a script?

解决方案

Entity Framework 5.0 isn't out yet. There are prereleases, but you need to specifically enable prereleases in order for NuGet to display them.

However, keep in mind that EF 5.0 won't support everything in .NET 4.0 that it will in .NET 4.5. Yes, .NET 4.5 overwrites .NET 4.0, but if your project is in VS2010, it will be configured to build for .NET 4.0, not .NET 4.5. It cannot assume .NET 4.5 features, because the result needs to run on systems that don't have .NET 4.5. You're targeting .NET 4.0, after all, and enum support isn't in the EntityFramework DLL you get from NuGet, it's in the System.Data.Entity DLL that's part of the .NET runtime, so it cannot be added in .NET 4.0. You can install the Visual Studio Beta to create applications that target .NET 4.5.

In short: "was told it's ok since 4.5 was an in-place install" -- no, it's not ok for your purposes.

这篇关于EF 5.0 Enums不生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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