实体框架DbContext代码生成生成不正确的代码 [英] Entity Framework DbContext code generation generates incorrect code

查看:97
本文介绍了实体框架DbContext代码生成生成不正确的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将VS2010与Entity Framework一起使用(文件版本为4.4。产品版本为5)

I'm using VS2010 with Entity Framework (file version is 4.4. product version is 5)

我已安装EF5.x DbContext 生成器。

I have installed the EF5.x DbContext generator.

创建我的 .edmx 文件后,右键单击空白空间并添加了新的 DbContext 模板,该模板生成了 context.tt .tt 文件。

After creating my .edmx file, I right clicked on the empty space and added a new DbContext template, which generated the context.tt and .tt files.

但是,在 .tt 文件中,这是自动生成的代码的样子:

However, in the .tt files, this is how the auto generated code looks like:

namespace DataObjects.EntityFramework.Models
{
    using System;
    using System.Collections.Generic;

    public partial class SubSystem
    {
        public string SubSystemId { get; set; }
        public string Description { get; set; }
        public string Fmode { get; set; }
        public Nullable<System.DateTime> LastBackup { get; set; }
    }
}

问题在于using语句位于名称空间,这会引起编译错误。

The problem is that the using statements are inside the namespace, which gives rise to a compilation error.

推荐答案

这些编译错误必须与其他内容有关,因为在C#中使用命名空间中的语句是完全合法的。

Those compilation errors must be related to something else, because it's perfectly legal in C# to have using statements in the namespace.

验证您已添加所有正确的引用例如EntityFramework.dll

Verify that you've added all of the correct references, such as EntityFramework.dll

这篇关于实体框架DbContext代码生成生成不正确的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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