Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在Neo4jclient中使用变异密码更新整个节点_C#_Neo4j_Cypher_Neo4jclient - Fatal编程技术网

C# 在Neo4jclient中使用变异密码更新整个节点

C# 在Neo4jclient中使用变异密码更新整个节点,c#,neo4j,cypher,neo4jclient,C#,Neo4j,Cypher,Neo4jclient,我需要使用变异密码更新给定节点的所有属性。我想离开Node和NodeReference,因为我知道它们不推荐使用,所以不能使用IGraphClient.Update。我对变异密码很陌生。我用C#编写,使用Neo4jclient作为Neo4j的接口 我编写了以下代码来更新“resunit”的“Name”属性,其中属性“UniqueId”等于2。这个很好用。然而, *我的resunit对象有许多属性 *我不知道哪些属性已更改 *我正在尝试编写能够处理不同类型对象(具有不同属性)的代码 使用IGrap

我需要使用变异密码更新给定节点的所有属性。我想离开Node和NodeReference,因为我知道它们不推荐使用,所以不能使用IGraphClient.Update。我对变异密码很陌生。我用C#编写,使用Neo4jclient作为Neo4j的接口

我编写了以下代码来更新“resunit”的“Name”属性,其中属性“UniqueId”等于2。这个很好用。然而,
*我的resunit对象有许多属性
*我不知道哪些属性已更改
*我正在尝试编写能够处理不同类型对象(具有不同属性)的代码

使用IGraphClient.Update可以传入整个对象,它将负责创建设置所有属性的密码

我也能用变异密码传递我的对象吗? 我能看到的唯一替代方法是对对象进行反射,以查找所有属性并为每个属性生成.Set,这是我希望避免的。请告诉我我是不是走错了路

        string newName = "A welcoming home";

        var query2 = agencyDataAccessor
                    .GetAgencyByKey(requestingUser.AgencyKey)
                    .Match("(agency)-[:HAS_RESUNIT_NODE]->(categoryResUnitNode)-[:THE_UNIT_NODE]->(resunit)")
                    .Where("resunit.UniqueId = {uniqueId}")
                    .WithParams(new { uniqueId = 2 })
                    .With("resunit")
                    .Set("resunit.Name = {residentialUnitName}")
                    .WithParams(new { residentialUnitName = newName });

        query2.ExecuteWithoutResults();
确实可以通过整个对象!下面我有一个名为
Thing
的对象,定义如下:

public class Thing
{
    public int Id { get; set; }
    public string Value { get; set; }
    public DateTimeOffset Date { get; set; }
    public int AnInt { get; set; }
}
然后,下面的代码创建一个新的
对象
并将其插入数据库,然后使用一个
Set
命令将其取回并更新:

Thing thing = new Thing{AnInt = 12, Date = new DateTimeOffset(DateTime.Now), Value = "Foo", Id = 1};

gc.Cypher
    .Create("(n:Test {thingParam})")
    .WithParam("thingParam", thing)
    .ExecuteWithoutResults();

var thingRes = gc.Cypher.Match("(n:Test)").Where((Thing n) => n.Id == 1).Return(n => n.As<Thing>()).Results.Single();
Console.WriteLine("Found: {0},{1},{2},{3}", thingRes.Id, thingRes.Value, thingRes.AnInt, thingRes.Date);

thingRes.AnInt += 100;
thingRes.Value = "Bar";
thingRes.Date = thingRes.Date.AddMonths(1);

gc.Cypher
    .Match("(n:Test)")
    .Where((Thing n) => n.Id == 1)
    .Set("n = {thingParam}")
    .WithParam("thingParam", thingRes)
    .ExecuteWithoutResults();

var thingRes2 = gc.Cypher.Match("(n:Test)").Where((Thing n) => n.Id == 1).Return(n => n.As<Thing>()).Results.Single();
Console.WriteLine("Found: {0},{1},{2},{3}", thingRes2.Id, thingRes2.Value, thingRes2.AnInt, thingRes2.Date);
所有属性都很好地更新了

Found: 1,Foo,12,2014-03-27 15:37:49 +00:00
Found: 1,Bar,112,2014-04-27 15:37:49 +00:00