I have 3 table which are Timetable, Schedule and Consultation slot
and i wish to combine them so that all the data are able to retrieve easily
Timetable are having
1. TimetableID
2. Lecture ID
3. ClassVenue
4. ClassStartTime
5. ClassEndTime
Schedule
1. ScheduleID
2. LectureID
3. ScheduleVenue
4. ScheduleStartTime
5. ScheduleEndTime
Consultation Slot
1. ConsultationID
2. LectureID
3. StudentID
4. ScheduleID
5. remark
Here is my code in metadata
Partial Public Class CombinationOfTSC
<Key()> _
Public Property LectureID() As String
Get
Return m_LectureID
End Get
Set(value As String)
m_LectureID = value
End Set
End Property
Private m_LectureID As String
Public Property StudentID() As String
Get
Return m_StudentID
End Get
Set(value As String)
m_StudentID = value
End Set
End Property
Private m_StudentID As String
Public Property ttID() As String
Get
Return m_ttID
End Get
Set(value As String)
m_ttID = value
End Set
End Property
Private m_ttID As String
Public Property ttClassVenue() As String
Get
Return m_ttClassVenue
End Get
Set(value As String)
m_ttClassVenue = value
End Set
End Property
Private m_ttClassVenue As String
Public Property ttClassStartTime() As DateTime
Get
Return m_ttClassStartTime
End Get
Set(value As DateTime)
m_ttClassStartTime = value
End Set
End Property
Private m_ttClassStartTime As DateTime
Public Property ttClassEndTime() As DateTime
Get
Return m_ttClassEndTime
End Get
Set(value As DateTime)
m_ttClassEndTime = value
End Set
End Property
Private m_ttClassEndTime As DateTime
Public Property scID() As String
Get
Return m_scID
End Get
Set(value As String)
m_scID = value
End Set
End Property
Private m_scID As String
Public Property scVenue() As String
Get
Return m_scVenue
End Get
Set(value As String)
m_scVenue = value
End Set
End Property
Private m_scVenue As String
Public Property scStartTime() As DateTime
Get
Return m_scStartTime
End Get
Set(value As DateTime)
m_scStartTime = value
End Set
End Property
Private m_scStartTime As DateTime
Public Property scEndTime() As DateTime
Get
Return m_scEndTime
End Get
Set(value As DateTime)
m_scEndTime = value
End Set
End Property
Private m_scEndTime As DateTime
Public Property cID() As String
Get
Return m_cID
End Get
Set(value As String)
m_cID = value
End Set
End Property
Private m_cID As String
Public Property cRemark() As String
Get
Return m_cRemark
End Get
Set(value As String)
m_cRemark = value
End Set
End Property
Private m_cRemark As String
End Class
In my domain class the code will be
Public Function GetCoTSC(lectureID As String) As IQueryable(Of CombinationOfTSC)
Dim CSC As IQueryable(Of CombinationOfTSC) = From c In ObjectContext.ConsultationSlots Join s In ObjectContext.Schedules On c.ScheduleID Equals s.ScheduleID Join t In ObjectContext.TimeTables On t.LectureID Equals s.LectureID Where c.LectureID = s.LectureID = t.LectureID Select New CombinationOfTSC() With { _
.cID = c.ConsultationID, _
.cRemark = c.Remark, _
.StudentID = c.StudentID, _
.LectureID = s.LectureID, _
.scStartTime = s.ScheduleStartTime, _
.scEndTime = s.ScheduleEndTime, _
.scID = s.ScheduleID, _
.scVenue = s.ScheduleVenue, _
.ttID = t.TimeTableID, _
.ttClassVenue = t.ClassVenue, _
.ttClassStartTime = t.ClassStartTime, _
.ttClassEndTime = t.ClassEndTime}
Return CSC
End Function
I'm having error at c.LectureID = s.LectureID = t.LectureID
I wish to get the combination of 3 tables through the lectureID since there are lecture ID on 3 tables.
Anyone helps pls.
I don't believe you can have x=y=z. Have you tried seperating these out into pairs?
try Where c.LectureID = s.LectureID and s.LectureID = t.LectureID in stead of Where c.LectureID = s.LectureID = t.LectureID
Related
Using VB in .NET2
Public Class GroupSID
Private _groupName As String
Private _sid As String
Public Property GroupName() As String
Get
Return _groupName
End Get
Set(ByVal value As String)
_groupName = value
End Set
End Property
Public Property SID() As String
Get
Return _sid
End Get
Set(ByVal value As String)
_sid = value
End Set
End Property
End Class
After the list is populated I want to find the item with the matching groupName (there will be only 1)
Something like (pseudo VB/C#)
'Dim result As GroupSID = ListOfGroupSID.Find(x => x.GroupName == groupName)
https://msdn.microsoft.com/en-us/library/x0b5b5bc(v=vs.80).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1
from: http://www.codeproject.com/Articles/388257/Csharp-Tips-Using-delegate-in-List-Find-predicate
' expression expected error on Function(p)
Dim result As GroupSID = ListOfGroupSID.Find(Function(p) p.GroupName = groupName)
Problem is VB8/.NET2 doesn't allow this..
Anonymous function (lambda) aren't available in VB8/.Net2 so you have to define your predicate as a separate method :
Function BelongsToSameGroup(ByVal group As GroupSID) As Boolean
Return group.GroupName = groupName ' need to be accessible
End Function
' usage
Dim result As GroupSID = ListOfGroupSID.Find(AddressOf BelongsToSameGroup)
I'm trying to retrieve my other football attributes (crossing, dribbling, finishing, ball control) that haven't been requested as arguments in the constructor- reportID, playerID and comments are all that are required.
There are over 20 football attributes, so I've just included the first few for readability.
Report Class:
Public Class Report
Public Sub New(ByVal reportID As Integer, ByVal playerID As Integer, ByVal comments As String)
_ReportID = reportID
_PlayerID = playerID
_Comments = comments
End Sub
Private _ReportID As Integer = 0
Private _PlayerID As Integer = 0
Private _Comments As String = ""
Private _Crossing As Integer = 0
Private _Dribbling As Integer = 0
Private _Finishing As Integer = 0
Private _BallControl As Integer = 0
Public Property ReportID() As Integer
Get
Return _ReportID
End Get
Set(ByVal value As Integer)
_ReportID = value
End Set
End Property
Public Property PlayerID() As Integer
Get
Return _PlayerID
End Get
Set(ByVal value As Integer)
_PlayerID = value
End Set
End Property
Public Property Comments() As String
Get
Return _Comments
End Get
Set(ByVal value As String)
_Comments = value
End Set
End Property
Public Property Crossing() As Integer
Get
Return _Crossing
End Get
Set(ByVal value As Integer)
_Crossing = value
End Set
End Property
Public Property Dribbling() As Integer
Get
Return _Dribbling
End Get
Set(ByVal value As Integer)
_Dribbling = value
End Set
End Property
Public Property Finishing() As Integer
Get
Return _Finishing
End Get
Set(ByVal value As Integer)
_Finishing = value
End Set
End Property
Public Property BallControl() As Integer
Get
Return _BallControl
End Get
Set(ByVal value As Integer)
_BallControl = value
End Set
End Property
End Class
Below I realise I'm only adding reportID, playerID and comments to my typeList, which is why I'm getting all 0's for my other attributes. How do access the attributes as well?
Retrieving the data:
Private Function retrieveReport() As List(Of Report)
Dim typeList As New List(Of Report)
Dim Str As String = "SELECT * FROM Report ORDER BY PlayerID"
Try
Using conn As New SqlClient.SqlConnection(DBConnection)
conn.Open()
Using cmdQuery As New SqlClient.SqlCommand(Str, conn)
Using drResult As SqlClient.SqlDataReader = cmdQuery.ExecuteReader()
While drResult.Read
typeList.Add(New Report(drResult("ReportID"), drResult("PlayerID"), drResult("Comments")))
End While
End Using 'Automatically closes connection
End Using
End Using
Catch ex As Exception
MsgBox("Report Exception: " & ex.Message & vbNewLine & Str)
End Try
Return typeList
End Function
Private Sub setReport()
For Each rpt As Report In retrieveReport()
'*****General Information
UC_Menu_Scout1.txtComments.Text = rpt.Comments
'*****Technical
UC_Menu_Scout1.UcAttributes1.lblXCrossing.Text = rpt.Crossing
UC_Menu_Scout1.UcAttributes1.lblXDribbling.Text = rpt.Dribbling
UC_Menu_Scout1.UcAttributes1.lblXFinishing.Text = rpt.Finishing
UC_Menu_Scout1.UcAttributes1.lblXBallControl.Text = rpt.BallControl
UC_Menu_Scout1.UcAttributes1.lblXPassing.Text = rpt.Passing
UC_Menu_Scout1.UcAttributes1.lblXHeadingAccuracy.Text = rpt.HeadingAccuracy
UC_Menu_Scout1.UcAttributes1.lblXMarking.Text = rpt.Marking
UC_Menu_Scout1.UcAttributes1.lblXTackling.Text = rpt.Tackling
'*****Mental
UC_Menu_Scout1.UcAttributes1.lblXAggression.Text = rpt.Aggression
UC_Menu_Scout1.UcAttributes1.lblXPositioning.Text = rpt.Positioning
UC_Menu_Scout1.UcAttributes1.lblXAnticipation.Text = rpt.Anticipation
UC_Menu_Scout1.UcAttributes1.lblXComposure.Text = rpt.Composure
UC_Menu_Scout1.UcAttributes1.lblXVision.Text = rpt.Vision
UC_Menu_Scout1.UcAttributes1.lblXTeamwork.Text = rpt.Teamwork
UC_Menu_Scout1.UcAttributes1.lblXWorkRate.Text = rpt.WorkRate
'*****Physical
UC_Menu_Scout1.UcAttributes1.lblXPace.Text = rpt.Pace
UC_Menu_Scout1.UcAttributes1.lblXBalance.Text = rpt.Balance
UC_Menu_Scout1.UcAttributes1.lblXJumping.Text = rpt.Jumping
UC_Menu_Scout1.UcAttributes1.lblXStrength.Text = rpt.Strength
UC_Menu_Scout1.UcAttributes1.lblXStamina.Text = rpt.Stamina
Next
End Sub
I imagine it's not that hard, so any help would be appreciated please!
To add values to the properties, use With:
typeList.Add(New Report(drResult("ReportID"), drResult("PlayerID"), drResult("Comments")) With {.BallControl = drResult("BallControl"), .Dribbling = drResult("Dribbling")})
You need to assign the property values that you aren't providing to the constructor as arguments, or you can add arguments to the constructor. Try this -- instead of calling the constructor like this:
typeList.Add(New Report(drResult("ReportID"), drResult("PlayerID"), drResult("Comments")))
instead, do this:
dim rep = New Report(drResult("ReportID"), drResult("PlayerID"), drResult("Comments"))
.Crossing = drResult("Crossing")
'additional property assignments
With rep
End With
typeList.Add(rep)
I'm trying to do a Bing Image Search Application (Azure Version), and i can't make progress. The code language is vb.net. Basically what i'm doing is trying to edit this code, that actually worked. Any Solutions ?
Function ExecuteQuery() As Boolean
Dim esito As Boolean = False
Try
Dim query As String = System.Web.HttpUtility.UrlEncode("Inception Movie")
Dim skip As String = "10"
Dim urlBase As New Uri("https://api.datamarket.azure.com")
Dim accountKey As String = "tymv8z6jFSdo4eQ3vsS5r8SZAmFtA24e6dmfyvaLh3U"
Dim credentials As New NetworkCredential(accountKey, accountKey)
Dim dsc As New System.Data.Services.Client.DataServiceContext(urlBase)
dsc.Credentials = New NetworkCredential(accountKey, accountKey)
Dim urlSearch As Uri = New Uri(("https://api.datamarket.azure.com/Bing/Search/Image?Query=%27" + query + "%27&$skip=" + skip))
Dim webResults = dsc.Execute(Of WebResult)(urlSearch)
For Each result As WebResult In webResults
ListBox1.Items.Add(result.Title)
ListBox1.Items.Add(result.Description)
singleValue = singleValue + 1
Next
esito = True
Catch ex As Exception
esito = False
End Try
Return esito
End Function
Partial Public Class WebResult
Private _ID As Guid
Private _Title As [String]
Private _Description As [String]
Private _DisplayUrl As [String]
Private _Url As [String]
Private _MediaUrl As [String]
Public Property ID() As Guid
Get
Return Me._ID
End Get
Set(ByVal value As Guid)
Me._ID = value
End Set
End Property
Public Property Title() As [String]
Get
Return Me._Title
End Get
Set(ByVal value As [String])
Me._Title = value
End Set
End Property
Public Property Description() As [String]
Get
Return Me._Description
End Get
Set(ByVal value As [String])
Me._Description = value
End Set
End Property
Public Property DisplayUrl() As [String]
Get
Return Me._DisplayUrl
End Get
Set(ByVal value As [String])
Me._DisplayUrl = value
End Set
End Property
Public Property Url() As [String]
Get
Return Me._Url
End Get
Set(ByVal value As [String])
Me._Url = value
End Set
End Property
Public Property MediaUrl() As [String]
Get
Return Me._MediaUrl
End Get
Set(ByVal value As [String])
Me._MediaUrl = value
End Set
End Property
End Class
I now solved the puzzle, founded a simple way to do this thing just using an class file:
1 - Just download this file: http://www.getcodesamples.com/src/15958EA3/F43E1E1A
2 - Then add the same file to your project
3 - Add the following code:
Dim strBingKey As String = "xxxaccountkeyxxx"
Dim bingClass As New Bing.BingSearchContainer(New Uri("https://api.datamarket.azure.com/Bing/Search/"))
bingClass.Credentials = New NetworkCredential(strBingKey, strBingKey)
Dim query = bingClass.Image("Inception" + "Movie", Nothing, "en-us", "Off", Nothing, Nothing, Nothing)
Dim results = query.Execute()
For Each result In results
ListBox1.Items.Add(result.Title)
ListBox1.Items.Add(result.MediaUrl)
Console.WriteLine(result.Thumbnail) 'ThumbNail type, need to convert to use in result list
Next
Thank you all for the patience!
For a long time, I have been try to do this:
Private Sub Search()
'DataGrid1.ItemsSource = From k In Globals.Batchs.BatchList Where (CType(k.Category, String).ToLower().Contains(SearchByCategory.Text)) Select k
Dim tot As List(Of WorkMateLib.BatchLib.BatchItem) = Globals.Batchs.BatchList
If Not SearchByCategory.Text = "" Then
tot = From k As WorkMateLib.BatchLib.BatchItem In tot Where CType(k.Category, String).ToLower().Contains(SearchByCategory.Text) Select k
End If
If Not SearchByCourse.Text = "" Then
tot = From k In tot Where (CType(k.CourseName, String).ToLower().Contains(SearchByCourse.Text))
End If
If Not SearchByName.Text = "" Then
tot = From k In tot Where (CType(k.BatchName, String).ToLower().Contains(SearchByName.Text))
End If
If Not SearchByYear.Text = "" Then
tot = From k In tot Where (CType(k.DateStarted, Date).Year.ToString.ToLower.Contains(SearchByYear.Text))
End If
DataGrid1.ItemsSource = tot
End Sub
But is keep on throwing the following exception:
Unable to cast object of type 'WhereSelectListIterator`2[WorkMateLib.BatchLib.BatchItem,WorkMateLib.BatchLib.BatchItem]' to type 'System.Collections.Generic.List`1[WorkMateLib.BatchLib.BatchItem]'.
Could you please review and let me know where I am going wrong please.
Following is the code for the classes:
Namespace BatchLib
Public Class BatchItem
Dim _BatchID As String
Dim _BatchName As String
Dim _Category As String
Dim _CourseID As String
Dim _CourseName As String
Dim _StartDate As Date
Dim _StartDateFormated As String
Dim _Deleted As Boolean
#Region "Property"
Property BatchID
Get
Return _BatchID
End Get
Set(value)
_BatchID = value
End Set
End Property
Property BatchName
Get
Return _BatchName
End Get
Set(value)
_BatchName = value
End Set
End Property
Property Category
Get
Return _Category
End Get
Set(value)
_Category = value
End Set
End Property
Property CourseID
Get
Return _CourseID
End Get
Set(value)
_CourseID = value
End Set
End Property
Property DateStarted
Get
Return _StartDate
End Get
Set(value)
_StartDate = value
End Set
End Property
Property Deleted
Get
Return _Deleted
End Get
Set(value)
_Deleted = value
End Set
End Property
Property CourseName
Get
Return _CourseName
End Get
Set(value)
_CourseName = value
End Set
End Property
Property StartDateFormated
Get
Return _StartDateFormated
End Get
Set(value)
_StartDateFormated = value
End Set
End Property
#End Region
End Class
Public Class Batchs
Public BatchList As New List(Of BatchItem)
Public Function Contains(ByVal Batchname As String, ByVal CourseID As String)
For Each k As BatchItem In BatchList
If k.CourseID = CourseID And k.BatchName = Batchname Then
Return True
Exit Function
End If
Next
Return False
End Function
Public Function Contains(ByVal Batchname As String, ByVal CourseID As String, ByVal BatchID As String)
For Each k As BatchItem In BatchList
If k.CourseID = CourseID And k.BatchName = Batchname Then
If k.BatchID = BatchID Then
Else
Return True
Exit Function
End If
End If
Next
Return False
End Function
End Class
End Namespace
Thank you for your efforts. I am new to linq, so I may not be that good at it, your assistant and making me understand the mistake is heartily welcomed.
Exception does say exacly whats ur problem. Linq expression does not return List and its not assignable to List. Try surounding your whole expression in brackets and use ToList()
I've pieced together some information from other posts but I'm stuck.
The first part works fine. Basically I query the database using LINQ and then I loop through the results generating a report.
Dim results As System.Linq.IQueryable(Of Bud900Reports.tblBud_CONNECT)
If options.Type = reportType.Organization Then
results = From p In db.tblBud_CONNECTs _
Where p.TableOldName = "tblFY" & options.FiscalYear And p.DEPTID = options.GroupFilter _
Order By p.SOURCE_CODE, p.ROW_CODE_903 _
Select p
ElseIf options.Type = reportType.Division Then
'Here is my problem line
End If
For each result in results
'loop through code generating report
Next
Now instead of having three function with alot of dupelicate code, if the reportType is Division I want to run this query and put it into the results set.
results = (From p In db.tblBud_CONNECTs _
Where p.TableOldName = "tblFY" & options.FiscalYear And p.DIVISION_CODE = options.GroupFilter _
Group p By p.DIVISION_CODE, p.SOURCE_CODE, p.ROW_CODE_903 Into _
OrigEft = Sum(p.OrigEft), OrigAmt = Sum(p.OrigAmt), ABEft = Sum(p.ABEft), ABAmt = Sum(p.ABAmt) _
Order By DIVISION_CODE, SOURCE_CODE, ROW_CODE_903 _
Select DIVISION_CODE, SOURCE_CODE, ROW_CODE_903, OrigEft, OrigAmt, ABEft, ABAmt)
It's the same data just grouped and summed up. But it comes through as an anonymous type. I tried to do "select new tblBud_CONNECTs with {.DIVISION_CODE = DIVISION_CODE, ...}" but it gave me the error of "Explicit construction of entity type tblBud_CONNECTs is not allowed".
How can I do what I want? It seems that I should be able to. Thanks.
For completeness I'll answer my own question.
First I created a class to hold the results.
Private Class results
Private mDivCode As String
Public Property DivCode() As String
Get
Return mDivCode
End Get
Set(ByVal value As String)
mDivCode = value
End Set
End Property
Private mSourceCode As Short
Public Property SourceCode() As Short
Get
Return mSourceCode
End Get
Set(ByVal value As Short)
mSourceCode = value
End Set
End Property
Private mRowCode As Short
Public Property RowCode() As Short
Get
Return mRowCode
End Get
Set(ByVal value As Short)
mRowCode = value
End Set
End Property
Private mOrigEft As Decimal
Public Property OrigEft() As Decimal
Get
Return mOrigEft
End Get
Set(ByVal value As Decimal)
mOrigEft = value
End Set
End Property
Private mOrigAmt As Decimal
Public Property OrigAmt() As Decimal
Get
Return mOrigAmt
End Get
Set(ByVal value As Decimal)
mOrigAmt = value
End Set
End Property
Private mABEft As Decimal
Public Property ABEft() As Decimal
Get
Return mABEft
End Get
Set(ByVal value As Decimal)
mABEft = value
End Set
End Property
Private mABAmt As Decimal
Public Property ABAmt() As Decimal
Get
Return mABAmt
End Get
Set(ByVal value As Decimal)
mABAmt = value
End Set
End Property
End Class
Then I set a variable to hold the results.
Dim results As System.Linq.IQueryable(Of results)
Then I made my linq query fill up the results like so.
results = (From p In db.tblBud_CONNECTs _
Where p.TableOldName = "tblFY" & options.FiscalYear And p.DEPTID = options.GroupFilter _
Order By p.SOURCE_CODE, p.ROW_CODE_903 _
Select New results With {.DivCode = p.DIVISION_CODE, .SourceCode = p.SOURCE_CODE.Value, .RowCode = p.ROW_CODE_903.Value, _
.OrigEft = p.OrigEft.Value, .OrigAmt = p.OrigAmt.Value, .ABEft = p.ABEft.Value, .ABAmt = p.ABAmt.Value})
That's how I ended up doing what I wanted.
The solution is to create a collection of the Division instances and populate this collection using 'results'.
Then you can use the Attach method to enable change tracking for these entities.