我希望将包含对象和集合的复杂模型批量导入Neo4j。
我有以下型号:
public class PSNGame
{
public int EarnedPlatinum { get; set; }
public int EarnedGold { get; set; }
public int EarnedSilver { get; set; }
public int EarnedBronze { get; set; }
public int EarnedTotal { get; set; }
public int AvailablePlatinum { get; set; }
public int AvailableGold { get; set; }
public int AvailableSilver { get; set; }
public int AvailableBronze { get; set; }
public int AvailableTotal { get; set; }
public double PercentCompleteBronze { get; set; }
public double PercentCompleteSilver { get; set; }
public double PercentCompleteGold { get; set; }
public double PercentCompletePlatinum { get; set; }
public double PercentCompleteTotal { get; set; }
public DateTimeOffset LastUpdated { get; set; }
public string Platform { get; set; }
public string NPCOMMID { get; set; }
public string TitleName { get; set; }
public string TitleDetail { get; set; }
public string Image { get; set; }
public string LargeImage { get; set; }
// complex model parts
public GameInfo GameInfo { get; set; }
public GameCommon.Rating Rating { get; set; }
public IEnumerable<GameCommon.RatingDescriptor> RatingDescriptors { get; set; }
public IEnumerable<GameCommon.Genre> Genres { get; set; }
public IEnumerable<GameCommon.Publisher> Publishers { get; set; }
public IEnumerable<GameCommon.Developer> Developers { get; set; }
public PSNGame()
{
}
}
我使用此代码将游戏插入Neo4j,但是,它只能在没有复杂对象/集合的情况下运行:
var client = new GraphClient(new Uri("http://localhost:7474/db/data"));
client.Connect();
client.Cypher
.Match("(p:PSNProfile {PSNId : {profile}.PSNId})")
.ForEach(@"(game in {PSNGames} |
MERGE p-[:PLAYS {LastPlayed : game.LastUpdated}]->(g:PSNGame {NPCOMMID : game.NPCOMMID})-[:LOCALE]->(l:PSNGameLocalized {NPCOMMID : game.NPCOMMID})
SET g = game,
l = { NPCOMMID : game.NPCOMMID,
TitleName : game.TitleName,
TitleDetail : game.TitleDetail,
Locale : {locale}
})")
.WithParams(new
{
PSNGames = games.ToList(),
locale = locale,
profile = profile
})
.ExecuteWithoutResults();
我尝试过嵌套的FOREACH
子句,但这可能会非常快。此外,MERGE g-[:GAME_RATING]->g.Rating
的语法似乎并不正确,Neo4j抱怨存在无效的.
令牌。我的想法是使用.
访问器循环访问集合并访问特定属性,但它看起来并不像Cypher喜欢语法。
对于复杂类型,我想自动为复杂类型中包含的任何子对象/集合创建/更新关系/节点。有没有办法在Neo4jClient中执行此操作?
答案 0 :(得分:2)
有没有办法在Neo4jClient中执行此操作?
没有。 Neo4jClient是一个较低级别的驱动程序,有点像SqlClient
。如果你想要更多的ORM风格的行为,那将是一个更高级别的库,相当于像Entity Framework这样的东西。有一个名为Neo4jRepository的项目已经有一段时间了,该项目建立在Neo4jClient之上,但据我所知,它还没有针对Neo4j 2.0更新。