Showing Comma separated values from database in a textarea? - sql-server

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

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

WPF INotifyPropertyChanged not allowing null value

Using WPF and EF and new to both. I may use the wrong terminology.
Using the EF wizard and code generators, I set up an EF using several tables, one of which is a lookup table.
I set up a form with a datagrid for the user to edit items in this lookup table. An issue I'm having is that the user can edit a cell, then close the form, but the editing of the cell will not update the underlying SQL database. I researched INotifyPropertyChanged and it seemed to be what I needed.
I implemented INotifyPropertyChanged to class bound to the datagrid. Before the implementation, the datagrid displayed all null values. After implementation, a message displays when the first null value is read that a nullable object must have a value.
Code:
Public Property ProcedureName As String
Get
Return _ProcedureName
End Get
Set(value As String)
_ProcedureName = value
RaisePropertyChanged("ProcedureName")
End Set
End Property
Private _ProcedureName As String
The exception occurs at "_ProcedureName = value".
Entire class:
Imports System
Imports System.Collections.ObjectModel
Partial Public Class tlkpProcedures_PartB
Inherits PropertyChangedBase
Public Property CPT As String
Get
Return _CPT
End Get
Set(value As String)
_CPT = value
RaisePropertyChanged("CPT")
End Set
End Property
Private _CPT As String
Public Property ProcedureName As String
Get
Return _ProcedureName
End Get
Set(value As String)
_ProcedureName = value
RaisePropertyChanged("ProcedureName")
End Set
End Property
Private _ProcedureName As String
Public Property BillingAmount As Nullable(Of Decimal)
Get
Return _BillingAmount
End Get
Set(value As Nullable(Of Decimal))
_BillingAmount = value
RaisePropertyChanged("BillingAmount")
End Set
End Property
Private _BillingAmount As Decimal
Public Property UniqueID As Integer
Public Overridable Property tblBilling_PartB As ObservableCollection(Of tblBilling_PartB) = New ObservableCollection(Of tblBilling_PartB)
End Class
Any help or advice is appreciated.
I'm not very good at VB but it seems like you try to assign a Nullable ( value As Nullable(Of Decimal) ) to a non-nullable (Private _BillingAmount As Decimal).
You should either cast value as Decimal or define _BillingAmount as Nullable(Of Decimal).

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

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.

WPF: "None" option when Databinding with DataGridComboBoxColumn

This is what I want:
There is a combo-box column bound to the ApplicationKey property of ClassA.
ClassA.ApplicationKey is a Nullable<Int32>
The combo-box is populated with ApplicationTokens from a static function all.
An ApplicationToken has a ApplicationName and ApplicationKey property
When an item is selected in the drop-down, the ClassA.ApplicationKey property is set to the ApplicationToken.ApplicationKey on the selected item.
The "None" option is currently represented by a Null. This can be changed.
Current code
<DataGridComboBoxColumn
Header="Application"
SelectedValueBinding="{Binding ApplicationKey}"
SelectedValuePath="ApplicationKey"
DisplayMemberPath="ApplicationName"
ItemsSource="{Binding Source={x:Static app:ApplicationLookup.GetAllOrNone}}"/>
Currently the binding works, except that I cannot select the "None" item from the list. The combobox shows it, but doesn't do anything when I try to select it with the mouse.
What is the standard way to offer none in a bound combo-box?
I don't know if this is the standard way of doing things but it seems to work:
All ApplicationTokens inherit from Token
Token has a "PrimaryKey" property.
There is a NullToken class defined as such:
Public Class NullToken
Inherits Token
Private ReadOnly m_DisplayValue As String
Private Sub New(ByVal displayValue As String)
m_DisplayValue = displayValue
End Sub
Public Overrides Function ToString() As String
Return m_DisplayValue
End Function
Public Overrides ReadOnly Property PrimaryKey As Integer?
Get
Return Nothing
End Get
End Property
Public Shared ReadOnly BlankToken As New NullToken("")
Public Shared ReadOnly NoneToken As New NullToken("None")
Public Shared ReadOnly AllToken As New NullToken("All")
End Class
ApplicationLookup.GetAllOrNone returns a collection of Token with the correct NullToken as the first item.
What I have done when I needed a None or (Select All) type of user gesture for a comboBox is create some static value for the token and just bind to a collection that includes the token in the first position. Then account for it in whatever is handling the change in value:
public string MidfixText {
get { return _midfixText; }
set {
...
_filter(!_midfixText.Equals(Strings.ProjectSelection_MidfixChoice_SelectAll));
}
}
HTH,
Berryl

Resources