5.13.0
🔮 Preview Feature: Record to Object Mapping
This new feature allows records to be mapped to objects simply and without endless boilerplate. Please see this discussion for full details and instructions.
🔮 New convenience methods in preview
The following extension methods have been added in order to make code that deals with the IRecord
and IEntity
(implemented by both INode
and IRelationship
) interfaces more readable - for example, when writing custom mapping code. The Neo4j.Driver.Preview.Mapping
namespace must be referenced to use these methods.
IRecord.AsObject<T>()
Invokes the mapping functionality and returns an instance of T
mapped from the record. T
must have a parameterless constructor.
IRecord.GetValue<T>(string key)
Gets the value of the given key from the record, converting it to the given type. For example, the code record["name"].As<string>()
becomes record.GetValue<string>("name")
.
IRecord.GetXXXX(string key)
This is a group of extension methods for the most commonly used primitive types: GetString
, GetInt
, GetLong
, GetDouble
, GetFloat
and GetBool
. These just call GetValue<T>
for the type named in the method name, so record["name"].As<string>()
becomes record.GetString("name")
.
IEntity.GetValue<T>(string key)
Gets the value of the given key from the entity, converting it to the given type. For example, the code entity["name"].As<string>()
becomes entity.GetValue<string>("name")
.
IEntity.GetXXXX(string key)
The same group of methods as IRecord.GetXXXX
, but for an entity.
IRecord.GetEntity(string key)
Gets the IEntity
identified by the given key from the record. When combined with the other methods, this can lead to more readable code that gets values from entities within records, so for example this code:
var name = record["person"].As<IEntity>().Properties["name"].As<string>();
becomes:
var name = record.GetEntity("person").GetString("name");