neo4j / neo4j-dotnet-driver

Neo4j Bolt driver for .NET
Apache License 2.0
231 stars 68 forks source link

Support for Guid and Enum #801

Open bar10dr opened 6 months ago

bar10dr commented 6 months ago

When trying to store an object with a Guid or Enum I get a driver respons that it does not support the types.

From looking around, it seems like in order to use these normal .net types, every user of official neo4j driver has to implement their own cast of these types in order to use them.

Wouldn't it be better if the driver provided this out of the box, so every single user doesn't have to implement their own variation?

If neo4j in the far future perhaps decides to implement these types, if you made the conversion manually or not makes no difference, either you would continue using the conversion to string, or you would have to migrate your data over. It would make no difference if the conversion was built into the driver or not.

At the very least documentation on how to do this would be appreciated.

thedomeffm commented 2 months ago

I think it is a very important feature that should be provided by the neo4j team.

:+1:

thedomeffm commented 2 months ago

I struggle with a mapper for Guids. (https://github.com/neo4j/neo4j-dotnet-driver/discussions/816)

@bar10dr did you got it running?

It seems like i am doing something wrong. MappingFailedException

public class GuidMappingProvider : IMappingProvider
{
    public void CreateMappers(IMappingRegistry registry)
    {
        registry
            .RegisterMapping<Skill>(
                builder =>
                {
                    builder
                        .UseDefaultMapping()
                        // this does not work:
                        .Map(m => m.nodeId, record => Guid.Parse(record.Values["nodeId"].As<string>()))
                        // this also does not work
                        .Map( m => m.nodeId, "nodeId", EntityMappingSource.Property, o => Guid.Parse(o.As<string>()), true)
                    ;
                });
    }
}