2016-12-15 82 views
1

我正在使用.net 4.5.50938 Visual Studio Community 2013 V12.0.31101.00更新4 操作系統:Win 7 我正在嘗試我從VS2012現有的網站複製到VS2013使用Visual 2013無法從其他部分類訪問部分類.net C#


項目/解決方案使用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! 
     } 

    } 


} 
+2

'createEntityClass1'是局部類之外。這根本無效。你不能有命名空間內的方法。 –

+0

感謝您的答覆,實際上這是一個錯字,我編輯它。問題依然存在。 – Araz

+0

您是否成功完成遷移?是否包含「csproj」文件? 。檢查是否包含所有'cs'文件。你也應該打開'sln'文件。 –

回答

0

您放置類定義之外的方法,因此沒有任何成員可用。

試試這個:

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

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

} 
+0

問題依然存在。在我的第一篇文章中,我輸錯了,你輸入的正是我所擁有的,但是標題沒有出現! – Araz

+0

我相信有某些項目配置會導致App_Code被視爲文本。我可能錯了,但請將該課程移到該文件夾​​之外,然後再試一次以確保。 – Licht

+0

我終於找到了解決方案! – Araz