{"id":186,"date":"2019-01-12T15:32:20","date_gmt":"2019-01-12T15:32:20","guid":{"rendered":"http:\/\/www.edcortes.ph\/?p=771"},"modified":"2021-07-10T03:30:09","modified_gmt":"2021-07-10T03:30:09","slug":"count-records-using-linq","status":"publish","type":"post","link":"https:\/\/emcortes.com\/?p=186","title":{"rendered":"Count records using LINQ"},"content":{"rendered":"<p>I need to get the number of Tasks in a project for the MaxValue property of Telerik ProgressBar and the numbers of completed tasks for its Value property. Below are the codes I used:<\/p>\n<pre>Public Sub progressBar()\r\nDim projectID As String = Me.txtID.Text\r\nDim db As New ProjectsEntities()\r\nDim totalTasks = Aggregate task In db.tblTasks\r\nWhere task.ProjectID = projectID\r\nInto Count()\r\nDim totalTasksCompleted = Aggregate task In db.tblTasks\r\nWhere task.ProjectID = projectID And \r\ntask.TaskStatus = \"Completed\"\r\nInto Count()\r\nMe.TaskProgressBar.Value = totalTasksCompleted\r\nMe.TaskProgressBar.MaxValue = totalTasks\r\nMe.TaskProgressBar.ChunksCount = totalTasks\r\nEnd Sub\r\n<\/pre>\n<p>For Average and Sum, below are codes copied from Microsoft Site.<\/p>\n<pre>\r\nDim averageOrderCount = Aggregate cust In db.Customers\r\n                        Where cust.City = \"London\"\r\n                        Into Average(cust.Orders.Count)\r\nmsg &= \"Average number of Orders per customer: \" &\r\n       averageOrderCount & vbCrLf\r\n\r\nDim venezuelaTotalOrders = Aggregate cust In db.Customers\r\n                           Where cust.Country = \"Venezuela\"\r\n                           Into Sum(cust.Orders.Count)\r\nmsg &= \"Total number of orders from Customers in \r\n       Venezuela: \" & venezuelaTotalOrders & vbCrLf\r\n\r\nMsgBox(msg)\r\n\r\nDim averageCustomersByCity = From cust In db.Customers\r\n                             Group By cust.City\r\n                             Into Average(cust.Orders.Count)\r\n                             Order By Average\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I need to get the number of Tasks in a project for the MaxValue property of Telerik ProgressBar and the numbers of completed tasks for its Value property. Below are the codes I used: Public Sub progressBar() Dim projectID As String = Me.txtID.Text Dim db As New ProjectsEntities() Dim totalTasks = Aggregate task In db.tblTasks [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,4],"tags":[],"class_list":["post-186","post","type-post","status-publish","format-standard","hentry","category-asp-net","category-programming-notes"],"_links":{"self":[{"href":"https:\/\/emcortes.com\/index.php?rest_route=\/wp\/v2\/posts\/186","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/emcortes.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/emcortes.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/emcortes.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/emcortes.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=186"}],"version-history":[{"count":1,"href":"https:\/\/emcortes.com\/index.php?rest_route=\/wp\/v2\/posts\/186\/revisions"}],"predecessor-version":[{"id":223,"href":"https:\/\/emcortes.com\/index.php?rest_route=\/wp\/v2\/posts\/186\/revisions\/223"}],"wp:attachment":[{"href":"https:\/\/emcortes.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=186"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/emcortes.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=186"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/emcortes.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=186"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}