Say I have a simple POCO class:
Public Class Person
Public Property Id As Integer
Public Property Name As String
Public Property Age As Integer
End Class
I would like to return a list of these objects in JSON format, but each object also needs a UUID, so using a LINQ Select statement, I create a new anoynmous types that include all properties from Person
, plus the addtional UUID
field. I'm wondering if there is a shorter way to create such a type. Ex:
Public Function GetPeople() As JsonResult
Dim people = _personRepository.GetAllPeople()
' Shorter way to write the statement below?
' EG something like "people.Select(Function(x) x.Merge(New With { .uuid = Guid.NewGuid() })"
Return Json(people.Select(Function(x) New With {
x.Id,
x.Name,
x.Age,
.uuid = Guid.NewGuid().ToString()
}, JsonRequestBehavior.AllowGet)
End Function
I'm fine with code examples in VB or C#