Data Entity Model question

wjburke2

Active member
Joined
Feb 3, 2009
Messages
29
Programming Experience
Beginner
I am working through a tutorial I found on this fourm posted by mendhak in 2008. I am working on the second lesson and for some reason the code to return the number of Article's is always 0. I ran a query and the first two authors should have 2 articles each. is there some reason this does not work?

articleCountLabel.Text = currentAuthor.Article.Count.ToString()

The complete code is at
Tutorial: An Introduction to the ADO.NET Entity Framework [Archive] - VBForums

Here is a short version.
Imports System.Data.Objects
Imports System.Data.Objects.DataClasses

Public Class PayrollView2

Dim publishContext As New PublishingCompanyEntities
Dim authorList As New List(Of Author)
Dim currentAuthorIndex As Integer = 0

Private Sub PayrollView2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim authorQuery As ObjectQuery(Of Author) = publishContext.Author.Where("it.FirstName <> 'Mark'")
authorList = authorQuery.ToList()
PopulateFields()

End Sub

Private Sub PayrollView2_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles
MyBase.FormClosed
publishContext.Dispose()

End Sub


Private Sub PopulateFields()

Dim currentAuthor As Author = authorList(currentAuthorIndex)

firstName.Text = currentAuthor.FirstName
lastName.Text = currentAuthor.LastName
authorIDLabel.Text = currentAuthor.AuthorID.ToString()
articleCountLabel.Text = currentAuthor.Article.Count.ToString()

End Sub
 
cjard thank you for your reply, Actually I found the anwser in the next lesson.
Dim authorQuery As ObjectQuery(Of Author) = publishContext.Author.Where("it.FirstName <> 'Mark'") only returns Aurthor's.
Dim authorQuery As ObjectQuery(Of Author) = publishContext.Author.Where("it.FirstName <> 'Mark'").Include("Article") returns Author's and Artical's. Again thank you for your reply I should have posted a reply with solution when found the answer.
 
Back
Top