LINQ to EF (Entify Framework) does not create partial methods "OnColumnChanged" - wpf

I have created a LINQ to EF model (to be used as the model in an mvvm wpf application) but the classes for each table do not contain on[columnname]changed or on[columnname]changing methods. I thought these were auto generated by the framework. I wanted to add to some of my own public partial methods in order to create some data validation as shown in the following page: http://blogs.msdn.com/b/bethmassi/archive/2009/07/07/implementing-validation-in-wpf-on-entity-framework-entities.aspx
The following class is an example of the auto generated code from EF.
Imports System
Imports System.Collections.Generic
Partial Public Class client
Public Property idClient As Integer
Public Property chrFirst As String
Public Property chrLast As String
Public Property chrCompany As String
Public Property chrEmail As String
Public Property chrPhone1 As String
Public Property chrPhone1Ext As String
Public Property chrPhone2 As String
Public Property chrPhone2Ext As String
Public Property chrFax As String
Public Property chrSuite As String
Public Property chrAddess As String
Public Property chrCity As String
Public Property chrProvince As String
Public Property chrCountry As String
Public Property chrPostal As String
Public Property dtCreated As Nullable(Of Date)
Public Property dtUpdated As Nullable(Of Date)
Public Property FTC_Type As Nullable(Of Byte)
Public Overridable Property invoices As ICollection(Of invoice) = New HashSet(Of invoice)
Public Overridable Property jobs As ICollection(Of job) = New HashSet(Of job)
End Class
When I add a partial public class of the same name I can see all the declarations of the original class generated by the EF in the declarations dropdown in the upper right hand corner fo the window in visual studio.
1- Does LINQ to EF work this way?
2- I am using vb.net 4 and visual studio 2012, is there another way of doing this?
Thanks in advance

which template are you using to generate the files?
The Self Tracking Entities are best-suited for use in a client/server WPF application, because they implement INotifyPropertyChanged and allow for disconnected (n-tier) change tracking.

Related

How can I put a JSON into an Array?

I have a question.
I have an JSON-Text in a variable.
How can I do it in a string array?
JSON-Query:
JSON-Query results
My Code
Dim wc As New System.Net.WebClient
Dim s As String = wc.DownloadString("http://transport.opendata.ch/v1/connections?from=" & textBox1.Text & "&to=" & textBox2.Text)
If you are going to be using different parts of the JSON you could build a model to represent the data and then deserialize into that model. For instance, you can generate a model from the JSON provided: (there are a number of services to do this online)
Public Class Coordinate
Public Property type As String
Public Property x As Double
Public Property y As Double
End Class
Public Class Station
Public Property id As String
Public Property name As String
Public Property score As Object
Public Property coordinate As Coordinate
Public Property distance As Object
End Class
Public Class Prognosis
Public Property platform As Object
Public Property arrival As Object
Public Property departure As DateTime?
Public Property capacity1st As Object
Public Property capacity2nd As Object
End Class
Public Class Location
Public Property id As String
Public Property name As String
Public Property score As Object
Public Property coordinate As Coordinate
Public Property distance As Object
End Class
Public Class From
Public Property station As Station
Public Property arrival As Object
Public Property arrivalTimestamp As Object
Public Property departure As DateTime
Public Property departureTimestamp As Integer
Public Property delay As Integer?
Public Property platform As String
Public Property prognosis As Prognosis
Public Property realtimeAvailability As Object
Public Property location As Location
End Class
Public Class [To]
Public Property station As Station
Public Property arrival As DateTime
Public Property arrivalTimestamp As Integer
Public Property departure As Object
Public Property departureTimestamp As Object
Public Property delay As Object
Public Property platform As String
Public Property prognosis As Prognosis
Public Property realtimeAvailability As Object
Public Property location As Location
End Class
Public Class PassList
Public Property station As Station
Public Property arrival As DateTime?
Public Property arrivalTimestamp As Integer?
Public Property departure As DateTime?
Public Property departureTimestamp As Integer?
Public Property delay As Integer?
Public Property platform As String
Public Property prognosis As Prognosis
Public Property realtimeAvailability As Object
Public Property location As Location
End Class
Public Class Journey
Public Property name As String
Public Property category As String
Public Property subcategory As Object
Public Property categoryCode As Object
Public Property number As String
Public Property [operator] As String
Public Property [to] As String
Public Property passList As List(Of PassList)
Public Property capacity1st As Object
Public Property capacity2nd As Object
End Class
Public Class Departure
Public Property station As Station
Public Property arrival As Object
Public Property arrivalTimestamp As Object
Public Property departure As DateTime
Public Property departureTimestamp As Integer
Public Property delay As Integer?
Public Property platform As String
Public Property prognosis As Prognosis
Public Property realtimeAvailability As Object
Public Property location As Location
End Class
Public Class Arrival
Public Property station As Station
Public Property arrival As DateTime
Public Property arrivalTimestamp As Integer
Public Property departure As Object
Public Property departureTimestamp As Object
Public Property delay As Integer?
Public Property platform As String
Public Property prognosis As Prognosis
Public Property realtimeAvailability As Object
Public Property location As Location
End Class
Public Class Section
Public Property journey As Journey
Public Property walk As Object
Public Property departure As Departure
Public Property arrival As Arrival
End Class
Public Class Connection
Public Property from As From
Public Property [to] As [To]
Public Property duration As String
Public Property transfers As Integer
Public Property service As Object
Public Property products As List(Of String)
Public Property capacity1st As Object
Public Property capacity2nd As Object
Public Property sections As List(Of Section)
End Class
Public Class Stations
Public Property from As List(Of From)
Public Property [to] As List(Of [To])
End Class
Public Class RootObject
Public Property connections As List(Of Connection)
Public Property from As From
Public Property [to] As [To]
Public Property stations As Stations
End Class
And then deserialize using JSON.NET into these models. Firstly, install the NuGet package Newtonsoft.Json and then add an import to it:
Imports Newtonsoft.Json
Then deserialise:
Dim wc As New System.Net.WebClient
Dim s As String = wc.DownloadString("http://transport.opendata.ch/v1/connections?from=" & textBox1.Text & "&to=" & textBox2.Text)
Dim journey = JsonConvert.DeserializeObject(Of RootObject)(s)
You can now access every part of the JSON using the model. For instance:
journey.connections.Count <-- gives you the number of connections (4 in your example)
Guessing a bit at the data I believe this will give you start and end date/times of the first and last connection (i.e. the whole journey):
journey.connections.First().from.departure
journey.connections.Last().to.arrival
The red field is for first departure Time (Not Date)
The yellow field is for first arrival Time (Not Date)
The black field is for second departure Time (Not Date)
The green field is for second arrival Time (Not Date)
The blue field is for third departure Time (Not Date)
The violet field is for third arrival Time (Not Date)
That is, what I want. How can I get this Data?
My entire string:
{"connections":[{"from":{"station":{"id":"8505000","name":"Luzern","score":null,"coordinate":{"type":"WGS84","x":47.050165,"y":8.310172},"distance":null},"arrival":null,"arrivalTimestamp":null,"departure":"2019-11-21T14:27:00+0100","departureTimestamp":1574342820,"delay":0,"platform":"14","prognosis":{"platform":null,"arrival":null,"departure":"2019-11-21T14:27:00+0100","capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8505000","name":"Luzern","score":null,"coordinate":{"type":"WGS84","x":47.050165,"y":8.310172},"distance":null}},"to":{"station":{"id":"8508392","name":"Dallenwil","score":null,"coordinate":{"type":"WGS84","x":46.933766,"y":8.392058},"distance":null},"arrival":"2019-11-21T14:52:00+0100","arrivalTimestamp":1574344320,"departure":null,"departureTimestamp":null,"delay":null,"platform":"14","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8508392","name":"Dallenwil","score":null,"coordinate":{"type":"WGS84","x":46.933766,"y":8.392058},"distance":null}},"duration":"00d00:25:00","transfers":0,"service":null,"products":["S4"],"capacity1st":null,"capacity2nd":null,"sections":[{"journey":{"name":"S4 21454","category":"S","subcategory":null,"categoryCode":null,"number":"4","operator":"ZB","to":"Wolfenschiessen","passList":[{"station":{"id":"8505000","name":"Luzern","score":null,"coordinate":{"type":"WGS84","x":47.050165,"y":8.310172},"distance":null},"arrival":null,"arrivalTimestamp":null,"departure":"2019-11-21T14:27:00+0100","departureTimestamp":1574342820,"delay":0,"platform":"14","prognosis":{"platform":null,"arrival":null,"departure":"2019-11-21T14:27:00+0100","capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8505000","name":"Luzern","score":null,"coordinate":{"type":"WGS84","x":47.050165,"y":8.310172},"distance":null}},{"station":{"id":"8508321","name":"Luzern Allmend\/Messe","score":null,"coordinate":{"type":"WGS84","x":47.035078,"y":8.303309},"distance":null},"arrival":"2019-11-21T14:29:00+0100","arrivalTimestamp":1574342940,"departure":"2019-11-21T14:29:00+0100","departureTimestamp":1574342940,"delay":1,"platform":null,"prognosis":{"platform":null,"arrival":null,"departure":"2019-11-21T14:30:00+0100","capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8508321","name":"Luzern Allmend\/Messe","score":null,"coordinate":{"type":"WGS84","x":47.035078,"y":8.303309},"distance":null}},{"station":{"id":"8516351","name":"Kriens Mattenhof","score":null,"coordinate":{"type":"WGS84","x":47.026602,"y":8.30237},"distance":null},"arrival":"2019-11-21T14:31:00+0100","arrivalTimestamp":1574343060,"departure":"2019-11-21T14:31:00+0100","departureTimestamp":1574343060,"delay":1,"platform":null,"prognosis":{"platform":null,"arrival":null,"departure":"2019-11-21T14:32:00+0100","capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8516351","name":"Kriens Mattenhof","score":null,"coordinate":{"type":"WGS84","x":47.026602,"y":8.30237},"distance":null}},{"station":{"id":"8508319","name":"Horw","score":null,"coordinate":{"type":"WGS84","x":47.017463,"y":8.306971},"distance":null},"arrival":"2019-11-21T14:33:00+0100","arrivalTimestamp":1574343180,"departure":"2019-11-21T14:33:00+0100","departureTimestamp":1574343180,"delay":1,"platform":null,"prognosis":{"platform":null,"arrival":null,"departure":"2019-11-21T14:34:00+0100","capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8508319","name":"Horw","score":null,"coordinate":{"type":"WGS84","x":47.017463,"y":8.306971},"distance":null}},{"station":{"id":"8508318","name":"Hergiswil","score":null,"coordinate":{"type":"WGS84","x":46.982608,"y":8.310167},"distance":null},"arrival":"2019-11-21T14:40:00+0100","arrivalTimestamp":1574343600,"departure":"2019-11-21T14:40:00+0100","departureTimestamp":1574343600,"delay":1,"platform":null,"prognosis":{"platform":null,"arrival":null,"departure":"2019-11-21T14:41:00+0100","capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8508318","name":"Hergiswil","score":null,"coordinate":{"type":"WGS84","x":46.982608,"y":8.310167},"distance":null}},{"station":{"id":"8508390","name":"Stansstad","score":null,"coordinate":{"type":"WGS84","x":46.976253,"y":8.336336},"distance":null},"arrival":"2019-11-21T14:44:00+0100","arrivalTimestamp":1574343840,"departure":"2019-11-21T14:44:00+0100","departureTimestamp":1574343840,"delay":0,"platform":null,"prognosis":{"platform":null,"arrival":null,"departure":"2019-11-21T14:44:00+0100","capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8508390","name":"Stansstad","score":null,"coordinate":{"type":"WGS84","x":46.976253,"y":8.336336},"distance":null}},{"station":{"id":"8508391","name":"Stans","score":null,"coordinate":{"type":"WGS84","x":46.958316,"y":8.366742},"distance":null},"arrival":"2019-11-21T14:48:00+0100","arrivalTimestamp":1574344080,"departure":"2019-11-21T14:48:00+0100","departureTimestamp":1574344080,"delay":0,"platform":null,"prognosis":{"platform":null,"arrival":null,"departure":"2019-11-21T14:48:00+0100","capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8508391","name":"Stans","score":null,"coordinate":{"type":"WGS84","x":46.958316,"y":8.366742},"distance":null}},{"station":{"id":"8508392","name":"Dallenwil","score":null,"coordinate":{"type":"WGS84","x":46.933766,"y":8.392058},"distance":null},"arrival":"2019-11-21T14:52:00+0100","arrivalTimestamp":1574344320,"departure":null,"departureTimestamp":null,"delay":0,"platform":"1","prognosis":{"platform":null,"arrival":"2019-11-21T14:52:00+0100","departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8508392","name":"Dallenwil","score":null,"coordinate":{"type":"WGS84","x":46.933766,"y":8.392058},"distance":null}}],"capacity1st":null,"capacity2nd":null},"walk":null,"departure":{"station":{"id":"8505000","name":"Luzern","score":null,"coordinate":{"type":"WGS84","x":47.050165,"y":8.310172},"distance":null},"arrival":null,"arrivalTimestamp":null,"departure":"2019-11-21T14:27:00+0100","departureTimestamp":1574342820,"delay":0,"platform":"14","prognosis":{"platform":null,"arrival":null,"departure":"2019-11-21T14:27:00+0100","capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8505000","name":"Luzern","score":null,"coordinate":{"type":"WGS84","x":47.050165,"y":8.310172},"distance":null}},"arrival":{"station":{"id":"8508392","name":"Dallenwil","score":null,"coordinate":{"type":"WGS84","x":46.933766,"y":8.392058},"distance":null},"arrival":"2019-11-21T14:52:00+0100","arrivalTimestamp":1574344320,"departure":null,"departureTimestamp":null,"delay":0,"platform":"1","prognosis":{"platform":null,"arrival":"2019-11-21T14:52:00+0100","departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8508392","name":"Dallenwil","score":null,"coordinate":{"type":"WGS84","x":46.933766,"y":8.392058},"distance":null}}}]},{"from":{"station":{"id":"8505000","name":"Luzern","score":null,"coordinate":{"type":"WGS84","x":47.050165,"y":8.310172},"distance":null},"arrival":null,"arrivalTimestamp":null,"departure":"2019-11-21T15:10:00+0100","departureTimestamp":1574345400,"delay":null,"platform":"13","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8505000","name":"Luzern","score":null,"coordinate":{"type":"WGS84","x":47.050165,"y":8.310172},"distance":null}},"to":{"station":{"id":"8508392","name":"Dallenwil","score":null,"coordinate":{"type":"WGS84","x":46.933766,"y":8.392058},"distance":null},"arrival":"2019-11-21T15:29:00+0100","arrivalTimestamp":1574346540,"departure":null,"departureTimestamp":null,"delay":null,"platform":"13","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8508392","name":"Dallenwil","score":null,"coordinate":{"type":"WGS84","x":46.933766,"y":8.392058},"distance":null}},"duration":"00d00:19:00","transfers":0,"service":null,"products":["IR"],"capacity1st":null,"capacity2nd":null,"sections":[{"journey":{"name":"IR 2976","category":"IR","subcategory":null,"categoryCode":null,"number":"IR 2976","operator":"ZB","to":"Engelberg","passList":[{"station":{"id":"8505000","name":"Luzern","score":null,"coordinate":{"type":"WGS84","x":47.050165,"y":8.310172},"distance":null},"arrival":null,"arrivalTimestamp":null,"departure":"2019-11-21T15:10:00+0100","departureTimestamp":1574345400,"delay":null,"platform":"13","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8505000","name":"Luzern","score":null,"coordinate":{"type":"WGS84","x":47.050165,"y":8.310172},"distance":null}},{"station":{"id":"8508391","name":"Stans","score":null,"coordinate":{"type":"WGS84","x":46.958316,"y":8.366742},"distance":null},"arrival":"2019-11-21T15:23:00+0100","arrivalTimestamp":1574346180,"departure":"2019-11-21T15:24:00+0100","departureTimestamp":1574346240,"delay":null,"platform":null,"prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8508391","name":"Stans","score":null,"coordinate":{"type":"WGS84","x":46.958316,"y":8.366742},"distance":null}},{"station":{"id":"8508392","name":"Dallenwil","score":null,"coordinate":{"type":"WGS84","x":46.933766,"y":8.392058},"distance":null},"arrival":"2019-11-21T15:29:00+0100","arrivalTimestamp":1574346540,"departure":null,"departureTimestamp":null,"delay":null,"platform":"2","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8508392","name":"Dallenwil","score":null,"coordinate":{"type":"WGS84","x":46.933766,"y":8.392058},"distance":null}}],"capacity1st":null,"capacity2nd":null},"walk":null,"departure":{"station":{"id":"8505000","name":"Luzern","score":null,"coordinate":{"type":"WGS84","x":47.050165,"y":8.310172},"distance":null},"arrival":null,"arrivalTimestamp":null,"departure":"2019-11-21T15:10:00+0100","departureTimestamp":1574345400,"delay":null,"platform":"13","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8505000","name":"Luzern","score":null,"coordinate":{"type":"WGS84","x":47.050165,"y":8.310172},"distance":null}},"arrival":{"station":{"id":"8508392","name":"Dallenwil","score":null,"coordinate":{"type":"WGS84","x":46.933766,"y":8.392058},"distance":null},"arrival":"2019-11-21T15:29:00+0100","arrivalTimestamp":1574346540,"departure":null,"departureTimestamp":null,"delay":null,"platform":"2","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8508392","name":"Dallenwil","score":null,"coordinate":{"type":"WGS84","x":46.933766,"y":8.392058},"distance":null}}}]},{"from":{"station":{"id":"8505000","name":"Luzern","score":null,"coordinate":{"type":"WGS84","x":47.050165,"y":8.310172},"distance":null},"arrival":null,"arrivalTimestamp":null,"departure":"2019-11-21T15:27:00+0100","departureTimestamp":1574346420,"delay":null,"platform":"14","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8505000","name":"Luzern","score":null,"coordinate":{"type":"WGS84","x":47.050165,"y":8.310172},"distance":null}},"to":{"station":{"id":"8508392","name":"Dallenwil","score":null,"coordinate":{"type":"WGS84","x":46.933766,"y":8.392058},"distance":null},"arrival":"2019-11-21T15:52:00+0100","arrivalTimestamp":1574347920,"departure":null,"departureTimestamp":null,"delay":null,"platform":"14","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8508392","name":"Dallenwil","score":null,"coordinate":{"type":"WGS84","x":46.933766,"y":8.392058},"distance":null}},"duration":"00d00:25:00","transfers":0,"service":null,"products":["S4"],"capacity1st":null,"capacity2nd":null,"sections":[{"journey":{"name":"S4 21458","category":"S","subcategory":null,"categoryCode":null,"number":"4","operator":"ZB","to":"Wolfenschiessen","passList":[{"station":{"id":"8505000","name":"Luzern","score":null,"coordinate":{"type":"WGS84","x":47.050165,"y":8.310172},"distance":null},"arrival":null,"arrivalTimestamp":null,"departure":"2019-11-21T15:27:00+0100","departureTimestamp":1574346420,"delay":null,"platform":"14","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8505000","name":"Luzern","score":null,"coordinate":{"type":"WGS84","x":47.050165,"y":8.310172},"distance":null}},{"station":{"id":"8508321","name":"Luzern Allmend\/Messe","score":null,"coordinate":{"type":"WGS84","x":47.035078,"y":8.303309},"distance":null},"arrival":"2019-11-21T15:29:00+0100","arrivalTimestamp":1574346540,"departure":"2019-11-21T15:29:00+0100","departureTimestamp":1574346540,"delay":null,"platform":null,"prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8508321","name":"Luzern Allmend\/Messe","score":null,"coordinate":{"type":"WGS84","x":47.035078,"y":8.303309},"distance":null}},{"station":{"id":"8516351","name":"Kriens Mattenhof","score":null,"coordinate":{"type":"WGS84","x":47.026602,"y":8.30237},"distance":null},"arrival":"2019-11-21T15:31:00+0100","arrivalTimestamp":1574346660,"departure":"2019-11-21T15:31:00+0100","departureTimestamp":1574346660,"delay":null,"platform":null,"prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8516351","name":"Kriens Mattenhof","score":null,"coordinate":{"type":"WGS84","x":47.026602,"y":8.30237},"distance":null}},{"station":{"id":"8508319","name":"Horw","score":null,"coordinate":{"type":"WGS84","x":47.017463,"y":8.306971},"distance":null},"arrival":"2019-11-21T15:33:00+0100","arrivalTimestamp":1574346780,"departure":"2019-11-21T15:33:00+0100","departureTimestamp":1574346780,"delay":null,"platform":null,"prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8508319","name":"Horw","score":null,"coordinate":{"type":"WGS84","x":47.017463,"y":8.306971},"distance":null}},{"station":{"id":"8508318","name":"Hergiswil","score":null,"coordinate":{"type":"WGS84","x":46.982608,"y":8.310167},"distance":null},"arrival":"2019-11-21T15:40:00+0100","arrivalTimestamp":1574347200,"departure":"2019-11-21T15:40:00+0100","departureTimestamp":1574347200,"delay":null,"platform":null,"prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8508318","name":"Hergiswil","score":null,"coordinate":{"type":"WGS84","x":46.982608,"y":8.310167},"distance":null}},{"station":{"id":"8508390","name":"Stansstad","score":null,"coordinate":{"type":"WGS84","x":46.976253,"y":8.336336},"distance":null},"arrival":"2019-11-21T15:44:00+0100","arrivalTimestamp":1574347440,"departure":"2019-11-21T15:44:00+0100","departureTimestamp":1574347440,"delay":null,"platform":null,"prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8508390","name":"Stansstad","score":null,"coordinate":{"type":"WGS84","x":46.976253,"y":8.336336},"distance":null}},{"station":{"id":"8508391","name":"Stans","score":null,"coordinate":{"type":"WGS84","x":46.958316,"y":8.366742},"distance":null},"arrival":"2019-11-21T15:48:00+0100","arrivalTimestamp":1574347680,"departure":"2019-11-21T15:48:00+0100","departureTimestamp":1574347680,"delay":null,"platform":null,"prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8508391","name":"Stans","score":null,"coordinate":{"type":"WGS84","x":46.958316,"y":8.366742},"distance":null}},{"station":{"id":"8508392","name":"Dallenwil","score":null,"coordinate":{"type":"WGS84","x":46.933766,"y":8.392058},"distance":null},"arrival":"2019-11-21T15:52:00+0100","arrivalTimestamp":1574347920,"departure":null,"departureTimestamp":null,"delay":null,"platform":"1","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8508392","name":"Dallenwil","score":null,"coordinate":{"type":"WGS84","x":46.933766,"y":8.392058},"distance":null}}],"capacity1st":null,"capacity2nd":null},"walk":null,"departure":{"station":{"id":"8505000","name":"Luzern","score":null,"coordinate":{"type":"WGS84","x":47.050165,"y":8.310172},"distance":null},"arrival":null,"arrivalTimestamp":null,"departure":"2019-11-21T15:27:00+0100","departureTimestamp":1574346420,"delay":null,"platform":"14","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8505000","name":"Luzern","score":null,"coordinate":{"type":"WGS84","x":47.050165,"y":8.310172},"distance":null}},"arrival":{"station":{"id":"8508392","name":"Dallenwil","score":null,"coordinate":{"type":"WGS84","x":46.933766,"y":8.392058},"distance":null},"arrival":"2019-11-21T15:52:00+0100","arrivalTimestamp":1574347920,"departure":null,"departureTimestamp":null,"delay":null,"platform":"1","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8508392","name":"Dallenwil","score":null,"coordinate":{"type":"WGS84","x":46.933766,"y":8.392058},"distance":null}}}]},{"from":{"station":{"id":"8505000","name":"Luzern","score":null,"coordinate":{"type":"WGS84","x":47.050165,"y":8.310172},"distance":null},"arrival":null,"arrivalTimestamp":null,"departure":"2019-11-21T16:10:00+0100","departureTimestamp":1574349000,"delay":null,"platform":"13","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8505000","name":"Luzern","score":null,"coordinate":{"type":"WGS84","x":47.050165,"y":8.310172},"distance":null}},"to":{"station":{"id":"8508392","name":"Dallenwil","score":null,"coordinate":{"type":"WGS84","x":46.933766,"y":8.392058},"distance":null},"arrival":"2019-11-21T16:29:00+0100","arrivalTimestamp":1574350140,"departure":null,"departureTimestamp":null,"delay":null,"platform":"13","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8508392","name":"Dallenwil","score":null,"coordinate":{"type":"WGS84","x":46.933766,"y":8.392058},"distance":null}},"duration":"00d00:19:00","transfers":0,"service":null,"products":["IR"],"capacity1st":null,"capacity2nd":null,"sections":[{"journey":{"name":"IR 2978","category":"IR","subcategory":null,"categoryCode":null,"number":"IR 2978","operator":"ZB","to":"Engelberg","passList":[{"station":{"id":"8505000","name":"Luzern","score":null,"coordinate":{"type":"WGS84","x":47.050165,"y":8.310172},"distance":null},"arrival":null,"arrivalTimestamp":null,"departure":"2019-11-21T16:10:00+0100","departureTimestamp":1574349000,"delay":null,"platform":"13","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8505000","name":"Luzern","score":null,"coordinate":{"type":"WGS84","x":47.050165,"y":8.310172},"distance":null}},{"station":{"id":"8508391","name":"Stans","score":null,"coordinate":{"type":"WGS84","x":46.958316,"y":8.366742},"distance":null},"arrival":"2019-11-21T16:23:00+0100","arrivalTimestamp":1574349780,"departure":"2019-11-21T16:24:00+0100","departureTimestamp":1574349840,"delay":null,"platform":null,"prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8508391","name":"Stans","score":null,"coordinate":{"type":"WGS84","x":46.958316,"y":8.366742},"distance":null}},{"station":{"id":"8508392","name":"Dallenwil","score":null,"coordinate":{"type":"WGS84","x":46.933766,"y":8.392058},"distance":null},"arrival":"2019-11-21T16:29:00+0100","arrivalTimestamp":1574350140,"departure":null,"departureTimestamp":null,"delay":null,"platform":"2","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8508392","name":"Dallenwil","score":null,"coordinate":{"type":"WGS84","x":46.933766,"y":8.392058},"distance":null}}],"capacity1st":null,"capacity2nd":null},"walk":null,"departure":{"station":{"id":"8505000","name":"Luzern","score":null,"coordinate":{"type":"WGS84","x":47.050165,"y":8.310172},"distance":null},"arrival":null,"arrivalTimestamp":null,"departure":"2019-11-21T16:10:00+0100","departureTimestamp":1574349000,"delay":null,"platform":"13","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8505000","name":"Luzern","score":null,"coordinate":{"type":"WGS84","x":47.050165,"y":8.310172},"distance":null}},"arrival":{"station":{"id":"8508392","name":"Dallenwil","score":null,"coordinate":{"type":"WGS84","x":46.933766,"y":8.392058},"distance":null},"arrival":"2019-11-21T16:29:00+0100","arrivalTimestamp":1574350140,"departure":null,"departureTimestamp":null,"delay":null,"platform":"2","prognosis":{"platform":null,"arrival":null,"departure":null,"capacity1st":null,"capacity2nd":null},"realtimeAvailability":null,"location":{"id":"8508392","name":"Dallenwil","score":null,"coordinate":{"type":"WGS84","x":46.933766,"y":8.392058},"distance":null}}}]}],"from":{"id":"8505000","name":"Luzern","score":null,"coordinate":{"type":"WGS84","x":47.050165,"y":8.310172},"distance":null},"to":{"id":"8508392","name":"Dallenwil","score":null,"coordinate":{"type":"WGS84","x":46.933766,"y":8.392058},"distance":null},"stations":{"from":[{"id":"8505000","name":"Luzern","score":null,"coordinate":{"type":"WGS84","x":47.050165,"y":8.310172},"distance":null}],"to":[{"id":"8508392","name":"Dallenwil","score":null,"coordinate":{"type":"WGS84","x":46.933766,"y":8.392058},"distance":null}]}}

In class design are nested classes always better?

The following item will be maintained in a Microsoft SQL Server database and developed using EF code first:
Is it always better to define the classes nested, meaning as below (abbreviated definitions to keep it simple), letting the database do the work of maintaining the relationships:
Public Class Assembly
Public Property assemblyID As Integer
Public Property parts As New List(Of Part)
End Class
Public Class Part
Public Property partID As Integer
Public Property subitems As New List(Of Subitem)
End Class
Public Class Subitem
Public Property subitemID As Integer
Public Property components As New List(Of Component)
End Class
Public Class Component
Public Property componentID As Integer
Public Property elements As New List(Of Element)
End Class
Public Class Element
Public Property elementID As Integer
Public Property Name As New List(Of String)
End Class
Or is there ever ANY reason to keep the classes separate and do the manual work of maintaining the relationship between the records in each class, meaning as below:
Public Class Assembly
Public Property assemblyID As Integer
Public Property parts As New List(Of Integer) 'which would be partIDs
End Class
Public Class Part
Public Property partID As Integer
Public Property subitems As New List(Of Integer) 'which would be subitemIDs
End Class
Public Class Subitem
Public Property subitemID As Integer
Public Property components As New List(Of Integer) 'which would be componentIDs
End Class
Public Class Component
Public Property componentID As Integer
Public Property elements As New List(Of Integer) 'which would be elementIDs
End Class
Public Class Element
Public Property elementID As Integer
Public Property Name As New List(Of String)
End Class
I have always assumed we should design classes that are nested to follow the structure of the actual data. But since this is a deeper nesting I thought I would ask in case there are other design approaches I should consider.
In this particular case, all of the records are unique. I.E. even though I made this look like it's an assembled part, I was just trying to name each level distinctly. But in this case, any one of these layer items will never be used in a different assembly.
If all your structures have the same depth then your model may be the best. Else consider hierarchical structure. Something like this.
Public Class PartModel
Public Property Id as Integer
Public Property Name As String
Public Property ParentId As Integer? ''Nullable(Of Integer)
<ForeignKey("ParentId")>
Public Property SubParts As List(Of PartModel) ''Note no **New** here. New will be in a Controller
End Class

Showing Comma separated values from database in a textarea?

I have really searched and searched and not found an answer. Given that one article can have multiple tags, I want to show the tags as comma separated values so that it looks like Egypt, Sinai, Muslim Brotherhoodin a textarea when the article is edited. I'll post whatever code is needed if that will help in the answer.
My model is:
Partial Public Class be_Posts
<Key>
Public Property PostRowID As Integer
Public Property BlogID As Guid
Public Property PostID As Guid
<StringLength(255)>
Public Property Title As String
Public Property Description As String
<AllowHtml> Public Property PostContent As String
Public Property DateCreated As Date?
Public Property DateModified As Date?
<StringLength(50)>
Public Property Author As String
Public Property IsPublished As Boolean?
Public Property IsCommentEnabled As Boolean?
Public Property Raters As Integer?
Public Property Rating As Single?
<StringLength(255)>
Public Property Slug As String
Public Property IsDeleted As Boolean
Public Overridable Property be_PostTag As ICollection(Of be_PostTag)
Public Overridable Property be_Categories As ICollection(Of be_Categories)
End Class
And the be_PostTag model
Partial Public Class be_PostTag
<Key>
Public Property PostTagID As Integer
Public Property BlogID As Guid
Public Property PostID As Guid
<StringLength(50)>
Public Property Tag As String
Public Property be_Posts As ICollection(Of be_Posts)
End Class
I am working with an existing database and data and the models were generated from Code First From Database.
I realize I will need an EditorTemplate but beyond that I don't know what to do. How would I bind multiple values to a single textarea?
An image to show what i am talking about:
Solved:
Tossed this into an editor template:
#modeltype IEnumerable(Of BetterBlog.Core.Entities.be_PostTag)
#code
Dim sb As New StringBuilder
For Each x In Model
Dim tags = x.Tag & IIf(x.Equals(Model.Last), "", ", ")
sb.Append(tags)
Next
#Html.TextArea("PostTags", sb.ToString, 10, 50, nothing)
End Code

CollectionViewSource as Class Property Type

I have a Class in my main WPF application which has a Property defined in the class as follows:
Public Class AppExample
Public PropertyName As CollectionViewSource
The project solution also inherits a Class Library (separate project but included in the solution and using the Inherits statement) - in the Class Library I want to do the same thing but I get an error.
Public Class ClassLibraryExample
Public PropertyName as CollectionViewSource
this results in:
Type 'CollectionViewSource' is not defined
How do I fix this?
Add the refernce of PresentationFramework.dll to your class library. It has namespace System.Windows.Data which contains CollectionViewSource
When you are using CollectionViewSource you have to use Data namespace(System.Windows.Data).

Binding to Class Item

This seems like it should be really basic but I can't seemto get it working.
I have a class file called XMLSource as follows:
Public Class XMLSource
Public Shared BrandItems As New MediaItems
Public Class MediaItems
Inherits ObservableCollection(Of MediaObject)
Implements INotifyPropertyChanged
End Class
End Class
Public Class MediaObject
Public Property Name As String
Public Property Title As String
End Class
The application reads an XML file and stores some items into XMLSource.BrandItems (happens on start-up).
I want to bind a Label control's Content property to XMLSource.BrandItems(0).Name
I tried:
<Label Content="{Binding Source={XMLSource},Path=.BrandItems[0].Src}" FontSize="20"></Label>
But it's not working.
Is it possible to bind directly like this?
You cannot contruct bindings like this, if you write {} that indicates a markup extension, further you cannot have static/shared members in a binding path. I think the correct binding would be:
{Binding [0].Src, Source={x:Static ns:XMLSource.BrandItems}}
x:Static is a markup extension which allows access of static members. (Note that this also allows access of fields unlike the Path which only allows public properties)
Where ns is declared in an xmlns attribute and points to the namespace of your XMLSource class.

Resources