【问题标题】:partial class is not accessible anymore from the other partial class using Visual 2013 .net C#部分类不再使用 Visual 2013 .net C# 从其他部分类访问
【发布时间】:2017-05-01 09:06:42
【问题描述】:

我正在使用 .net 4.5.50938 Visual Studio Community 2013 V12.0.31101.00 更新4 操作系统:赢 7 我正在尝试将我现有的网站从 VS2012 复制到 VS2013 中的项目/解决方案


使用 Visual Studio,我在“模型”文件夹中创建了一个来自数据库的实体模型,其中部分“EntityClass1”类作为其类之一。 现在我转到“App_Code”文件夹并添加一个名为“EntityClass1”的类,并添加与“EntityClass1”使用关键字相同的命名空间。但与 Visual Studio 2012 不同,我无法访问 EntityClass1 的属性!

//------------------------------------------------------------------------------
// <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 MyProjectToVs2013.Models
{
    using System;
    using System.Collections.Generic;

    public partial class EntityClass1
    {
        public System.Guid ID { get; set; }
        public string Title { get; set; }
        public System.Guid Class1ID { get; set; }

        public virtual Entity34 Entity34 { get; set; }
    }
}

在另一个EntityClass1中:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MyProjectToVs2013.Models;
using System.ComponentModel.DataAnnotations;

namespace MyProjectToVs2013.Models
{
    public partial class EntityClass1
    {
        public EntityClass1()
        { 
            //TODO: Add constructor logic here
        }  

        public void createEntityClass1()
        {
//here I am trying to access the properties and unlike VS2012
 I cannot!! there is no such properties available via intelliSense: 
        Title // not appearing!
        }

    }


}

【问题讨论】:

  • createEntityClass1 在部分类之外。这根本无效。你不能在命名空间中有方法。
  • 感谢您的回复,实际上这是一个错字,我对其进行了编辑。问题依然存在。
  • 迁移成功了吗?是否包含csproj 文件? .检查是否包含所有cs 文件。你也应该打开sln文件。
  • 您的代码对我来说很好用。 rextester.com/OZOO59727
  • @M.kazemAkhgary 正如我所提到的,我正在从网站项目迁移到解决方案项目,因此除了新创建的文件之外,没有要包含的 csproj 文件。

标签: c# .net visual-studio-2013 entity-framework-4


【解决方案1】:

您已将方法放在类定义之外,因此没有可用的成员。

试试这个:

public partial class EntityClass1
{
    public EntityClass1()
    { 
        //TODO: Add constructor logic here
    }

    public void createEntityClass1()
    {
        Title = "anything";
    }

}

【讨论】:

  • 问题依然存在。在我最初的帖子中,我有错字,你输入的正是我所拥有的,但标题没有出现!
  • 我相信某些项目配置会导致 App_Code 被视为文本。我可能错了,但请将课程移出该文件夹并重试以确保。
  • 好吧,我终于找到了解决方案!
  • 我需要转到 App_Code 和 Model 文件夹中的 EntityClass1 文件,并将两个文件的名为“NameSpace”的属性设置为“MyProjectToVs2013.Models”并重建项目。现在可以了 :) 来源:dzapart.blogspot.com.tr/2011/11/…
  • @Araz 请发布您自己问题的答案,然后选择它作为答案。这样一来,偶然发现这个问题的人就可以很容易地找到答案。
【解决方案2】:

我需要访问 App_Code 和 Model 文件夹中的 EntityClass1 文件 并将两个文件的名为“NameSpace”的属性设置为 “MyProjectToVs2013.Models”并重建项目。现在可以了:)

来源: http://dzapart.blogspot.com.tr/2011/11/creating-common-partial-class-with.html

【讨论】:

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