使用 Visual 2013 .net C# 无法再从另一个部分 class 访问部分 class

partial class is not accessible anymore from the other partial class using Visual 2013 .net C#

我正在使用.net 4.5.50938 Visual Studio 社区 2013 V12.0.31101.00 更新 4 OS: 赢 7 我正在尝试将现有网站从 VS2012 复制到 VS2013

中的 project/solution

使用 Visual studio 我在我的 'Models' 文件夹中创建了一个来自数据库的实体模型,其中有部分 'EntityClass1' class 作为其 class是的。 现在我转到 'App_Code' 文件夹并添加一个名为 'EntityClass1' 的 class 并添加与 '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!
        }

    }


}

您已将您的方法置于 class 定义之外,因此没有成员可用。

试试这个:

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

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

}

我需要转到 App_Code 和模型文件夹中的 EntityClass1 文件 并将两个文件的名为 'NameSpace' 的属性设置为 "MyProjectToVs2013.Models" 并重建项目。现在可以了:)

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