コード例 #1
0
 public IEnumerable <BindingPair <SqlStorageField <TEntity>, PropertyField> > GetBindingPairs(
     SqlStorageModel <TEntity> sourceModel,
     SqlEntityModel <TEntity> targetModel)
 {
     foreach (var targetField in targetModel.Fields)
     {
         var sourceField = sourceModel.Fields.FirstOrDefault(
             q => q.TypeModelGraphPath.Path.SequenceEqual(targetField.TypeModelGraphPath.Path)
             );
         if (sourceField != null)
         {
             var bindingSource = new ModelFieldBindingSource <SqlStorageField <TEntity> >(
                 new[] { sourceField.FieldName },
                 sourceField
                 );
             yield return(new BindingPair <SqlStorageField <TEntity>, PropertyField>(
                              bindingSource,
                              new ModelFieldBindingTarget <PropertyField>(targetField.TypeModelGraphPath.Path, targetField)
                              ));
         }
         else if (targetField.FieldModel != null && targetField.FieldModel.Fields.Count > 0)
         {
             foreach (var pair in GetBindingPairs(sourceModel, targetField.FieldModel))
             {
                 yield return(pair);
             }
         }
     }
 }
コード例 #2
0
        public bool TryPrepareForRead(ModelFieldBindingSource <TField> bindingSource)
        {
            var desiredGraphPosition = bindingSource.Path.Take(bindingSource.Path.Length - 1);

            if (desiredGraphPosition.SequenceEqual(_currentPosition))
            {
                //  no-op if already in position to read
                return(true);
            }

            //  todo: don't rely on exceptions here to control flow, it's naughty
            try
            {
                //  todo: optimize graph navigation
                //    for now we just seek to the top of the graph and descend back to where we want to be
                //    this can be done in fewer steps if the desired path and current path
                //    share a common root
                SeekToTop();
                SeekTo(desiredGraphPosition);
                return(true);
            }
            catch
            {
                return(false);
            }
        }