public async Task <TValue> Get <TValue>(Expression <Func <T, TValue> > expression) { var member = (expression.Body as MemberExpression).Member as PropertyInfo; var prop = PropCache.props[member.Name]; if ((LiveMode & LiveObjectMode.LiveRead) != 0) { IEnumerable <LiveDbObject <T> > results = (await Neo4jSet <T> .All(GraphClientFactory).Include(expression).ReturnAsync()).ToList(); IEnumerable <LiveDbObject <T> > filtered = results.Where(x => x["Id"] == this["Id"]).ToList(); TValue[] vals = await Task.WhenAll(filtered.Select(x => { LiveObjectMode oldMode = x.LiveMode; x.LiveMode = LiveObjectMode.Ignore; var ret = x.Get(expression); x.LiveMode = oldMode; return(ret); })); TValue remote = vals.SingleOrDefault(); if (!remote.Equals(default))
public static LiveDbObject <T> Build(T buildFor, Func <IDriver> graphClient, LiveObjectMode liveMode) { if (buildFor is INeo4jNode) { LiveDbObject <T> tmp = new LiveDbObject <T>(buildFor, graphClient, liveMode); LiveDbObject <T> pooled = livePool.Where(x => { if (Object.ReferenceEquals(x.BackingInstance, buildFor)) { return(true); } string strid = (buildFor as INeo4jNode).Id; if (string.IsNullOrWhiteSpace(strid)) { return(false); } else { return(x["Id"].ToString() == strid); } }).SingleOrDefault(); if (pooled == null) { livePool.Add(tmp); return(tmp); } else { return(pooled); } } //non-INeo4jNode objects don't get pooled return(new LiveDbObject <T>(buildFor, graphClient, liveMode)); }
private LiveDbObject(T backingInstance, Func <IDriver> graphClientFactory, LiveObjectMode liveMode) { BackingInstance = backingInstance; GraphClientFactory = graphClientFactory; LiveMode = liveMode; }