EF bug中生成的类的部分类?

时间:2014-01-02 10:51:52

标签: c# .net entity-framework

我习惯使用VB,它是C#语法的新手。但是从我到处读到的内容来看,部分类的语法似乎有点相似。

我正在尝试为使用Entity Framework生成的生成的部分类创建一个部分类。

好像我的班级无法到达另一个班级。

错误:

  

'XmasMVC.CmsSystemPagePart'不包含的定义   'DefaultLanguageCode'并没有扩展方法'DefaultLanguageCode'   接受“XmasMVC.CmsSystemPagePart”类型的第一个参数可以   找到(你错过了使用指令或汇编引用吗?)

我可以编译但是在运行时遇到错误。好像我的班级会覆盖生成的班级。

这是来自EF的基因治疗班。

//------------------------------------------------------------------------------
// <auto-generated>
//    This code was generated from a template.
//
//    Manual changes to this file may cause unexpected behavior in your application.
//    Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace XmasMVC
{
    using System;

    public partial class CmsSystemPagePart
    {
        public string DefaultLanguageCode { get; set; }
        public string PagePartName { get; set; }
        public string Description { get; set; }
        public string DefaultLangValue { get; set; }
        public string LanguageCode { get; set; }
        public string Value { get; set; }
    }
}

这是我的班级。

namespace XmasMVC
{
    using System;

    public partial class CmsSystemPagePart
    {
        public string GetValue()
        {
            if (this.Value == null)
                return this.DefaultLangValue;
            else return this.Value;
        }

        public string GetLanguageCode()
        {
            if (this.Value == null)
                return this.DefaultLanguageCode;
            else return this.LanguageCode;
        }
    }
}

发现这个“警告”:

  

“'C:\ VSS \ Comdigit \ Xmas \ XmasMVC \ App_Code \ CmsSystemPagePart.cs'中的类型'XmasMVC.CmsSystemPagePart'&gt;'与导入的&gt;类型冲突'XmasMVC.CmsSystemPagePart 'in'C:\ VSS \ Comdigit \ Xmas \ XmasMVC \'。使用'C:\ VSS \ Comdigit \ Xmas \ XmasMVC \ App_Code \ CmsSystemPagePart.cs中定义的&gt;类型“

对象浏览器的外观如下。对我来说很奇怪!

Object Browser

1 个答案:

答案 0 :(得分:0)

这里的

This链接解释了

  

通常,ASP.NET为每个应用程序目录(例如App_Code)创建一个程序集,为主目录创建一个程序集。

对于您的情况,虽然部分类在同一个项目中是相同的命名空间,但它们并没有被编译到同一个程序集中。

尝试将源文件移出App_Code,并确保属性窗口中的Build actionCompiled

相关问题