首先在ASP.Net MVC EF6数据库中使用VB.Net

时间:2014-02-15 13:43:13

标签: asp.net-mvc vb.net entity-framework

我是EF的一个完整的Noob,我正在尝试使用它来创建我的第一个应用程序,但我正在陷入第一个障碍,因为我正在尝试使用VB.NET而不是C#来学习它意味着绝对没有资源在那里。我遇到的问题是,当我尝试在VB中生成模型时,它实际上并不像它应该的那样填充。即显示在edmx文件夹下创建的所有文件。我用c#做了同样的事情,它运行正常,因为我可以看到已生成的所有.cs和.tt文件。那么有人能告诉我哪里出错了吗?我在VB而不是c#中这样做的原因仅仅是因为我对vb语法更加熟悉。

1 个答案:

答案 0 :(得分: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)

结束班