Stardust.Paradox.Data 2.3.2

Entityframework styled tool for accessing gremlin based graph databases like CosmosDB and Apache Tinkerpop

There is a newer version of this package available.
See the version list below for details.
Install-Package Stardust.Paradox.Data -Version 2.3.2
dotnet add package Stardust.Paradox.Data --version 2.3.2
<PackageReference Include="Stardust.Paradox.Data" Version="2.3.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Stardust.Paradox.Data --version 2.3.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Stardust.Paradox

Entity framework'ish tool for developing .net applications using gremlin graph query language with CosmosDb

Usage (asp.net core)

Startup.cs

ConfigureServices

Add the generated entity implementations to the IOC container (I will provide an extention method to make this easier)

 services.AddEntityBinding((entityType, entityImplementation) => services.AddTransient(entityType, entityImplementation))
        .AddScoped<MyEntityContext,MyEntityContext>()
        .AddScoped<IGremlinLanguageConnector>(s => new CosmosDbLanguageConnector(DbAccountName, AccessKey, "databaseName","collectionName"));

Defining the model

[VertexLabel("person")]
public interface IPerson : IVertex
{
    string Id {get;}

    string FirstName { get; set; }

    string LastName { get; set; }
    
    string Email { get; set; }

    EpochDateTime Birthday {get;set;}//Wrapper type for DateTime that serializes into unix epoch. Can be used in predicate steps directly.

    IEdgeCollection<IPerson> Parents { get; }

    IEdgeCollection<IPerson> Children { get; }

    IEdgeCollection<IPerson> Siblings { get; }

    [EdgeLabel("city")] //pointing to the Residents property in ICity
    IEdgeReference<ICity> HomeCity { get; }//use IEdgeReference to enable task-async operations

    IEdgeCollection<ICompany> Employers { get; }
}

[VertexLabel("city")]
public interface ICity : IVertex
{
    string Id { get; }

    string Name { get; set; }

    string ZipCode { get; set; }
    

   [ReverseEdgeLabel("city")] //pointing to the HomCity property in IPerson
    IEdgeCollection<Iperson> Residents { get; } //use IEdgeCollection to enable task-async operations on the collection

    IEdgeReference<ICountry> Country { get; }
}

[VertexLabel("company")]
public interface ICompany : IVertex
{
    string Id { get; }

    string Name { get; set; }

    IEdgeCollection<ICompany> Employees { get; }
}

[VertexLabel("country")]
public interface ICountry : IVertex
{
    string Id { get; }

    string Name { get; set; }

    string CountryCode { get; set; }

    string PhoneNoPrefix { get; set; }

    IEdgeCollection<ICity> Cities { get; }
}

 [EdgeLabel("employer")]
    public interface IEmployment : IEdge<IProfile, ICompany>
    {
        string Id { get; }

        EpochDateTime HiredDate { get; set; }

        string Manager { get; set; }
    }

Defining the entity context and generating the entity implementations

public class MyEntityContext : Stardust.Paradox.Data.GraphContextBase
{
    public IGraphSet<IPerson> Persons => GraphSet<IPerson>();

    public IGraphSet<ICity> Cities => GraphSet<ICity>();

    public IGraphSet<ICountry> Countries => GraphSet<ICountry>();

    public IGraphSet<ICompany> Companies => GraphSet<ICompany>();

    public IGraphSet<IEmployment> Employments => EdgeGraphSet<IEmployment>();

    public MyEntityContext(IGremlinLanguageConnector connector, IServiceProvider resolver) : base(connector, resolver)
    {
    }

    protected override bool InitializeModel(IGraphConfiguration configuration)
    {
        //Added some fluent configuration of the edges
        configuration.ConfigureCollection<IPerson>()
                .AddEdge(t => t.Children, "children").Reverse<IPerson>(t => t.Parents)
            .ConfigureCollection<ICity>()
            .ConfigureCollection<ICountry>()
                .AddEdge(t=>t.Cities).Reverse<ICountry>(t=>t.Country)
            .ConfigureCollection<ICompany>()
                .AddEdge(t => t.Employees, "employees").Reverse<IPerson>(t => t.Employers)
                .ConfigureCollection<IEmployment>();;
        return true;
    }
}

Using the datacontext


public class DemoController:Controller
{
    private MyEntityContext _dataContext;
    public DemoController(MyEntityContext dataContext)
    {
        _dataContext=dataContext;
    }

    public Task<IActionResult> GetDataAsync(string personId)
    {
        var person=await _dataContext.Persons.GetAsync(persionId);
        return new User
        {
            Id=person.Id,
            FirstName=person.FistName,
            LastName=person.LastName,
            Email=person.Email
        }
    }

    public Task<IActionResult> AddEmploymentAsync(string userId, string companyId,DateTime hiredDate, string managerName) //new in V2
    {
        var user=await await _dataContext.Persons.GetAsync(persionId);
        var company=await _dataContext.Companies.GetAsync(companyId);
        var e= _dataContext.Employments.Create(user,company);
        e.HiredDate=hiredDate.ToEpoch();
        e.ManagerName=managerName;
        await _dataContext.SaveChangesAsync();
        //alternative
        
    }

    public Task<IActionResult> AddEmploymentAlternativeAsync(string userId, string companyId,DateTime hiredDate, string managerName) //edge property handling in V1
    {
        var user=await await _dataContext.Persons.GetAsync(persionId);
        var company=await _dataContext.Companies.GetAsync(companyId);
        user.Employers.Add(company,new Dictionary<string,object>{
            {"hiredDate",hiredDate.ToEpoch()},
            {"managerName","managerName"}
        })
        await _dataContext.SaveChangesAsync();
        //alternative
        
    }
}

Dynamic graph entities

In many cases we cannot model our graph as strong typed entities. Paradox supports hybrid entities by adding IDynamicGraphEntity to your edge or vertex definition you can model the well known peroperties on your entities, but at the same time assign and manipulate arbitary properties. These properties enjoy the same treatment as the typed properties with regards to parameterization and change tracking.

[VertexLabel("person")]
    public interface IProfile : IVertex, IDynamicGraphEntity
    {
        string Id { get; }

        string FirstName { get; set; }

        string LastName { get; set; }

        string Email { get; set; }

        bool VerifiedEmail { get; set; }

        string Name { get; set; }

        string Ocupation { get; set; }

        DateTime LastUpdated { get; set; }

        //[EdgeLabel("parent")]
        IEdgeCollection<IProfile> Parents { get; }

        //[ReverseEdgeLabel("parent")]
        IEdgeCollection<IProfile> Children { get; }

        [ToWayEdgeLabel("spouce")]
        IEdgeReference<IProfile> Spouce { get; }

        [Eager]
        [EdgeLabel("employer")]
        ICollection<ICompany> Employers { get; }


        [GremlinQuery("g.V('{id}').as('s').in('parent').out('parent').where(without('s')).dedup()")]
        IEdgeCollection<IProfile> Siblings { get; }

        [InlineSerialization(SerializationType.ClearText)]
        ICollection<string> ProgramingLanguages { get; }

        IEdgeCollection<IProfile> AllSiblings { get; set; }

        bool Adult { get; set; }
        
        string Description { get; set; }
        
        int Number { get; set; }
	    
        string Pk { get; set; }
	    
        EpochDateTime LastUpdatedEpoch { get; set; }
    }

usage

 var profile = await tc.VAsync<IProfile>("myId");
 profile.SetProperty("someRandomProp",$"test+:{DateTime.UtcNow.Ticks}");
 Console.WriteLine(profile.GetProperty("someRandomProp"));
 Console.WriteLine(string.Join(",",profile.DynamicPropertyNames))

Stardust.Paradox

Entity framework'ish tool for developing .net applications using gremlin graph query language with CosmosDb

Usage (asp.net core)

Startup.cs

ConfigureServices

Add the generated entity implementations to the IOC container (I will provide an extention method to make this easier)

 services.AddEntityBinding((entityType, entityImplementation) => services.AddTransient(entityType, entityImplementation))
        .AddScoped<MyEntityContext,MyEntityContext>()
        .AddScoped<IGremlinLanguageConnector>(s => new CosmosDbLanguageConnector(DbAccountName, AccessKey, "databaseName","collectionName"));

Defining the model

[VertexLabel("person")]
public interface IPerson : IVertex
{
    string Id {get;}

    string FirstName { get; set; }

    string LastName { get; set; }
    
    string Email { get; set; }

    EpochDateTime Birthday {get;set;}//Wrapper type for DateTime that serializes into unix epoch. Can be used in predicate steps directly.

    IEdgeCollection<IPerson> Parents { get; }

    IEdgeCollection<IPerson> Children { get; }

    IEdgeCollection<IPerson> Siblings { get; }

    [EdgeLabel("city")] //pointing to the Residents property in ICity
    IEdgeReference<ICity> HomeCity { get; }//use IEdgeReference to enable task-async operations

    IEdgeCollection<ICompany> Employers { get; }
}

[VertexLabel("city")]
public interface ICity : IVertex
{
    string Id { get; }

    string Name { get; set; }

    string ZipCode { get; set; }
    

   [ReverseEdgeLabel("city")] //pointing to the HomCity property in IPerson
    IEdgeCollection<Iperson> Residents { get; } //use IEdgeCollection to enable task-async operations on the collection

    IEdgeReference<ICountry> Country { get; }
}

[VertexLabel("company")]
public interface ICompany : IVertex
{
    string Id { get; }

    string Name { get; set; }

    IEdgeCollection<ICompany> Employees { get; }
}

[VertexLabel("country")]
public interface ICountry : IVertex
{
    string Id { get; }

    string Name { get; set; }

    string CountryCode { get; set; }

    string PhoneNoPrefix { get; set; }

    IEdgeCollection<ICity> Cities { get; }
}

 [EdgeLabel("employer")]
    public interface IEmployment : IEdge<IProfile, ICompany>
    {
        string Id { get; }

        EpochDateTime HiredDate { get; set; }

        string Manager { get; set; }
    }

Defining the entity context and generating the entity implementations

public class MyEntityContext : Stardust.Paradox.Data.GraphContextBase
{
    public IGraphSet<IPerson> Persons => GraphSet<IPerson>();

    public IGraphSet<ICity> Cities => GraphSet<ICity>();

    public IGraphSet<ICountry> Countries => GraphSet<ICountry>();

    public IGraphSet<ICompany> Companies => GraphSet<ICompany>();

    public IGraphSet<IEmployment> Employments => EdgeGraphSet<IEmployment>();

    public MyEntityContext(IGremlinLanguageConnector connector, IServiceProvider resolver) : base(connector, resolver)
    {
    }

    protected override bool InitializeModel(IGraphConfiguration configuration)
    {
        //Added some fluent configuration of the edges
        configuration.ConfigureCollection<IPerson>()
                .AddEdge(t => t.Children, "children").Reverse<IPerson>(t => t.Parents)
            .ConfigureCollection<ICity>()
            .ConfigureCollection<ICountry>()
                .AddEdge(t=>t.Cities).Reverse<ICountry>(t=>t.Country)
            .ConfigureCollection<ICompany>()
                .AddEdge(t => t.Employees, "employees").Reverse<IPerson>(t => t.Employers)
                .ConfigureCollection<IEmployment>();;
        return true;
    }
}

Using the datacontext


public class DemoController:Controller
{
    private MyEntityContext _dataContext;
    public DemoController(MyEntityContext dataContext)
    {
        _dataContext=dataContext;
    }

    public Task<IActionResult> GetDataAsync(string personId)
    {
        var person=await _dataContext.Persons.GetAsync(persionId);
        return new User
        {
            Id=person.Id,
            FirstName=person.FistName,
            LastName=person.LastName,
            Email=person.Email
        }
    }

    public Task<IActionResult> AddEmploymentAsync(string userId, string companyId,DateTime hiredDate, string managerName) //new in V2
    {
        var user=await await _dataContext.Persons.GetAsync(persionId);
        var company=await _dataContext.Companies.GetAsync(companyId);
        var e= _dataContext.Employments.Create(user,company);
        e.HiredDate=hiredDate.ToEpoch();
        e.ManagerName=managerName;
        await _dataContext.SaveChangesAsync();
        //alternative
        
    }

    public Task<IActionResult> AddEmploymentAlternativeAsync(string userId, string companyId,DateTime hiredDate, string managerName) //edge property handling in V1
    {
        var user=await await _dataContext.Persons.GetAsync(persionId);
        var company=await _dataContext.Companies.GetAsync(companyId);
        user.Employers.Add(company,new Dictionary<string,object>{
            {"hiredDate",hiredDate.ToEpoch()},
            {"managerName","managerName"}
        })
        await _dataContext.SaveChangesAsync();
        //alternative
        
    }
}

Dynamic graph entities

In many cases we cannot model our graph as strong typed entities. Paradox supports hybrid entities by adding IDynamicGraphEntity to your edge or vertex definition you can model the well known peroperties on your entities, but at the same time assign and manipulate arbitary properties. These properties enjoy the same treatment as the typed properties with regards to parameterization and change tracking.

[VertexLabel("person")]
    public interface IProfile : IVertex, IDynamicGraphEntity
    {
        string Id { get; }

        string FirstName { get; set; }

        string LastName { get; set; }

        string Email { get; set; }

        bool VerifiedEmail { get; set; }

        string Name { get; set; }

        string Ocupation { get; set; }

        DateTime LastUpdated { get; set; }

        //[EdgeLabel("parent")]
        IEdgeCollection<IProfile> Parents { get; }

        //[ReverseEdgeLabel("parent")]
        IEdgeCollection<IProfile> Children { get; }

        [ToWayEdgeLabel("spouce")]
        IEdgeReference<IProfile> Spouce { get; }

        [Eager]
        [EdgeLabel("employer")]
        ICollection<ICompany> Employers { get; }


        [GremlinQuery("g.V('{id}').as('s').in('parent').out('parent').where(without('s')).dedup()")]
        IEdgeCollection<IProfile> Siblings { get; }

        [InlineSerialization(SerializationType.ClearText)]
        ICollection<string> ProgramingLanguages { get; }

        IEdgeCollection<IProfile> AllSiblings { get; set; }

        bool Adult { get; set; }
        
        string Description { get; set; }
        
        int Number { get; set; }
	    
        string Pk { get; set; }
	    
        EpochDateTime LastUpdatedEpoch { get; set; }
    }

usage

 var profile = await tc.VAsync<IProfile>("myId");
 profile.SetProperty("someRandomProp",$"test+:{DateTime.UtcNow.Ticks}");
 Console.WriteLine(profile.GetProperty("someRandomProp"));
 Console.WriteLine(string.Join(",",profile.DynamicPropertyNames))

Release Notes

Added support for typed Edges.
Added parameterized queries for connectors that support it, for connectors that doesnt support it input strings are escaped to avoid some injection attacks
Added support for partitioning (CosmosDB)
Added missing 'and' overload and fixed get edge partitioning issue.
Added missing 'and' overload
Bugfix: new TypedEdge is not saved when no properties are updated
Bugfix: Parameterization of numbers larger than int.MaxValue fails when calling cosmosDB
Enhancement: Added EpochDateTime type to handle datetime values better.
Enhancement: Added support for EpochDateTime in the appropriate predicate steps
Enhancement: Added support for text predicates
Enhancement: Removing restrictions requiring vertex and edge properties to have a setter (thanx @bittola)
Enhancement: added support for enums (thanx @adelzu)
Performance fixes

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
3.0.0-rc03 427 2/14/2020
3.0.0-rc01 121 2/14/2020
2.3.4 797 1/13/2020
2.3.3 159 1/8/2020
2.3.2 98 1/8/2020
2.3.1 87 1/7/2020
2.3.0 249 12/2/2019
2.2.0 121 11/12/2019
2.1.7 68 11/5/2019
2.1.6 90 10/8/2019
2.1.5 96 9/16/2019
2.1.4 104 8/13/2019
2.1.3 342 6/5/2019
2.1.2 132 5/28/2019
2.1.1 434 4/2/2019
2.1.0 149 4/2/2019
2.0.6 139 4/1/2019
2.0.5 171 3/27/2019
2.0.4 183 3/6/2019
2.0.0 174 2/20/2019
2.0.0-pre29 154 2/19/2019
2.0.0-pre26 138 2/14/2019
2.0.0-pre23 137 2/12/2019
2.0.0-pre15 145 2/6/2019
2.0.0-pre11 174 2/4/2019
2.0.0-pre09 164 1/25/2019
2.0.0-pre02 185 1/16/2019
2.0.0-pre01 222 12/5/2018
1.4.9 153 2/8/2019
1.4.8 256 12/6/2018
1.4.7 188 11/28/2018
1.4.5 180 11/21/2018
1.4.4 187 11/20/2018
1.4.3 207 11/6/2018
1.4.1 187 10/30/2018
1.4.0 196 10/22/2018
1.3.11 198 10/16/2018
1.3.5 201 10/15/2018
1.3.4 255 10/8/2018
1.3.3 258 10/2/2018
1.3.2 222 9/11/2018
1.3.1 303 8/23/2018
1.3.0 250 8/23/2018
1.2.0 232 8/20/2018
1.1.5 219 8/15/2018
1.0.4 213 8/14/2018
1.0.3 213 8/13/2018
1.0.2 205 8/13/2018
1.0.1 219 8/10/2018
1.0.0-pre005 313 7/3/2018
1.0.0-pre001 267 6/11/2018
Show less