我正在使用c#构建app以测试nosql数据库的性能。我正在尝试向模型插入大量集合,并创建关系,如第一个集合中的一个对象和第二个集合中的一个对象。
这些是我的模特:
public class Movie
{
public Guid Id { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public int Year { get; set; }
public string Genres { get; set; }
public int Rating { get; set; }
public string OriginalLanguage { get; set; }
public string ProductionCountry { get; set; }
public int VotingsNumber { get; set; }
}
public class Actor
{
public string Firstname { get; set; }
public string Lastname { get; set; }
public int Age { get; set; }
}
我正在尝试使用此代码执行此操作:
var moviesCollection = Movie.CreateMoviesCollectionForNeo4j(collectionEntriesNumber);
var actorsCollection = Movie.CreateActors(collectionEntriesNumber);
for (int j = 0; j < collectionEntriesNumber; j++)
{
_client.Cypher.Create("(movie:Movie {newMovie})").WithParam("newMovie", moviesCollection[j]).ExecuteWithoutResults();
_client.Cypher.Create("(actor:Actor {newActor})").WithParam("newActor", actorsCollection[j]).ExecuteWithoutResults();
_client.Cypher.Match("(movie:Movie)","(actor:Actor)").Where((Movie movie) => movie.Id == moviesCollection[j].Id).AndWhere((Actor actor) => actor.Firstname == actorsCollection[j].Firstname).CreateUnique("actor-[:STARTED_IN]->movie").ExecuteWithoutResults();
}
但我得到例外:
Unhandled node type MemberAccess in MemberExpression: value(NoSQLTesting.DatabaseHandlers.Neo4j+<>c__DisplayClass0).moviesCollection.get_Item(value(NoSQLTesting.DatabaseHandlers.Neo4j+<>c__DisplayClass2).j).Id
有人可以解释我的错误以及如何做对吗? 谢谢, P上。
答案 0 :(得分:0)
根据this similar question的答案,以下代码可能对您更有效(并且可能更高效):
var moviesCollection = Movie.CreateMoviesCollectionForNeo4j(collectionEntriesNumber);
var actorsCollection = Movie.CreateActors(collectionEntriesNumber);
for (int j = 0; j < collectionEntriesNumber; j++)
{
var currMovie = moviesCollection[j];
var currActor = actorsCollection[j];
_client.Cypher.Create("(movie:Movie {newMovie})").WithParam("newMovie", currMovie).ExecuteWithoutResults();
_client.Cypher.Create("(actor:Actor {newActor})").WithParam("newActor", currActor).ExecuteWithoutResults();
_client.Cypher.Match("(movie:Movie)","(actor:Actor)").Where((Movie movie) => movie.Id == currMovie.Id).AndWhere((Actor actor) => actor.Firstname == currActor.Firstname).CreateUnique("actor-[:STARTED_IN]->movie").ExecuteWithoutResults();
}