使用Visual 2013 .net C#从其他分部类不再可访问partial class

时间:2016-12-15 17:05:13

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

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

使用Visual Studio我有一个来自我的' Models'中创建的数据库的实体模型。具有部分' EntityClass1'的文件夹class作为其中一个类。 现在我去了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!
        }

    }


}

2 个答案:

答案 0 :(得分:1)

我需要在App_Code和Model文件夹中转到EntityClass1文件 并将两个文件的名称'NameSpace'设置为 “MyProjectToVs2013.Models”并重建项目。现在它有效:)

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

答案 1 :(得分:0)

您已将方法放在课程定义之外,因此没有会​​员可用。

试试这个:

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

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

}