2014-02-15 68 views
1

我是一個完整的Noob與EF和我試圖創建我的第一個應用程序使用它,但我在第一個障礙,因爲我試圖學習它使用它VB.NET而不是C#意味着那裏絕對沒有資源。我遇到的問題是,當我試圖在VB中生成模型時,它實際上並不像它應該的那樣填充。即顯示在edmx文件夾下創建的所有文件。我已經用c#試過同樣的東西,它能正常工作,因爲我可以看到所有生成的.cs和.tt文件。那麼有人可以告訴我哪裏會出錯嗎?我在VB而不是C#中完成這個工作的原因僅僅是因爲我對vb語法更加熟悉。在ASP.Net中使用VB.Net MVC EF6數據庫第一

+0

我會努力今天爲您發佈一些示例代碼。我建議切換到C#我曾經在VB代碼,但我強迫自己切換,並享受C#更好。 – VoltaicShock

+0

非常感謝!實際上掌握c#是我10年的計劃。 – user3313436

回答

0

我在下面粘貼了一些代碼。你還在找什麼?我更喜歡Fluent API方法。我喜歡使用這個工具:

http://visualstudiogallery.msdn.microsoft.com/72a60b14-1581-4b9b-89f2-846072eff19d

這裏是C#

public partial class Grade 
{ 
    public Grade() 
    { 
     this.Students = new List<Student>(); 
     this.Teachers = new List<Teacher>(); 
    } 

    public int GradeID { get; set; } 
    public string Name { get; set; } 
    public virtual ICollection<Student> Students { get; set; } 
    public virtual ICollection<Teacher> Teachers { get; set; } 
} 

下面的代碼是在VB代碼

Public Partial Class Grade 
Public Sub New() 
    Me.Students = New List(Of Student)() 
    Me.Teachers = New List(Of Teacher)() 
End Sub 

Public Property GradeID() As Integer 
    Get 
     Return m_GradeID 
    End Get 
    Set 
     m_GradeID = Value 
    End Set 
End Property 
Private m_GradeID As Integer 
Public Property Name() As String 
    Get 
     Return m_Name 
    End Get 
    Set 
     m_Name = Value 
    End Set 
End Property 
Private m_Name As String 
Public Overridable Property Students() As ICollection(Of Student) 
    Get 
     Return m_Students 
    End Get 
    Set 
     m_Students = Value 
    End Set 
End Property 
Private Overridable m_Students As ICollection(Of Student) 
Public Overridable Property Teachers() As ICollection(Of Teacher) 
    Get 
     Return m_Teachers 
    End Get 
    Set 
     m_Teachers = Value 
    End Set 
End Property 
Private Overridable m_Teachers As ICollection(Of Teacher) 

末級