Sql server 实体框架未创建SQL Server数据库
我正在Visual Studio.Net 2013社区版上试用Entity Framework 6.1.3。问题是没有创建数据库,并且DBSet类型的属性始终设置为Nothing 这是我的班级Sql server 实体框架未创建SQL Server数据库,sql-server,vb.net,entity-framework,Sql Server,Vb.net,Entity Framework,我正在Visual Studio.Net 2013社区版上试用Entity Framework 6.1.3。问题是没有创建数据库,并且DBSet类型的属性始终设置为Nothing 这是我的班级 Public Class ExpenseType Public Property ExpensTypeId As Integer Public Property ExpenseName As String Public Property IsOutgoing As Boolean
Public Class ExpenseType
Public Property ExpensTypeId As Integer
Public Property ExpenseName As String
Public Property IsOutgoing As Boolean
End Class
这是我的上下文类
Imports System.Data.Entity
Public Class ExpensesContext
Inherits DbContext
Public Property ExpenseTypes As DbSet(Of ExpenseType)
End Class
这是我的表格代码
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Using db As New ExpensesContext
Dim expensetype As New ExpenseType With
{
.ExpensTypeId = 0,
.ExpenseName = "ADDITIONAL FUND",
.IsOutgoing = False
}
**** value of ExpensesTypes is Nothing and generates NullReferenceException
db.ExpenseTypes.Add(expensetype)
db.SaveChanges()
End Using
End Sub
App.Config中的我的连接字符串
<connectionStrings>
<add name="ExpensesContext"
connectionString="Server=localhost;Integrated Security=SSPI;Database=ExpensesTracking"
providerName="System.Data.SqlClient"/>
</connectionStrings>
请帮忙
提前感谢。已解决。我忘了将属性放在DBSet变量中