Hi,
I am new to entity framework and found that the CodeFirst release is okay. So I decided to create a simple asp.net webforms application to test this. Populated a table with some data and tried to retrieve the data with the following code:
Imports System.Data.Entity
Public Class AdmonHRMDbContext
Inherits DbContext
Public Property Application_User As DbSet(Of User)
End Class
Public Class User
Public Property UserId As Int32
Public Property LoginName As String
Public Property Password As String
End Class
Public Class UserRepository
Private context As AdmonHRMDbContext
Public Sub New()
context = New AdmonHRMDbContext
End Sub
Public Function GetUsers() As IQueryable(Of User)
Return context.Application_User
End Function
End Class
Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
Dim u As New BusinessLogic.UserRepository()
GridView1.DataSource = u.GetUsers
GridView1.DataBind()
End Sub
below is the exception I got:
Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported. Instead populate a DbSet with data, for example by calling Load on the DbSet, and then bind to local data. For WPF bind to DbSet.Local. For WinForms bind to DbSet.Local.ToBindingList().
I don't know what to do please help
Aweklin