Пример #1
0
        public async Task Set <TValue>(Expression <Func <T, TValue> > expression, TValue value)
        {
            var member = (expression.Body as MemberExpression).Member as PropertyInfo;
            var prop   = PropCache.props[member.Name];

            Func <LiveDbObject <T>, TValue, Task> SaveTask = async(y, x) =>
            {
                if (x is INeo4jNode)
                {
                    await DBOps.SaveSubnode(this, prop, value, GraphClientFactory);
                }
                else if (typeof(TValue).IsEnumerable() && typeof(INeo4jNode).IsAssignableFrom(typeof(TValue).GetGenericArguments()[0]))
                {
                    await DBOps.SaveCollection(this, prop, value, GraphClientFactory);
                }
                else
                {
                    await DBOps.SaveValue(this, prop, value, GraphClientFactory);
                }
            };

            if ((LiveMode & LiveObjectMode.LiveWrite) != 0)
            {
                await SaveTask(this, value);
            }
            else if ((LiveMode & LiveObjectMode.DeferedWrite) != 0)
            {
                ThreadPool.QueueUserWorkItem(async _ =>
                {
                    await SaveTask(this, value);
                });
            }

            member.SetValue(BackingInstance, value);
        }
        public static async Task <bool> Save <T>(this LiveDbObject <T> buildFor, Func <IDriver> graphClientFactory) where T : INeo4jNode
        {
            await DBOps.SaveNode(buildFor, graphClientFactory);

            return(true);
        }