当前位置: 首页>>代码示例>>C#>>正文


C# DataStrategy类代码示例

本文整理汇总了C#中DataStrategy的典型用法代码示例。如果您正苦于以下问题:C# DataStrategy类的具体用法?C# DataStrategy怎么用?C# DataStrategy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DataStrategy类属于命名空间,在下文中一共展示了DataStrategy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Execute

 public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
 {
     var criteria = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), MethodNameParser.ParseFromBinder(binder, args));
     return new SimpleQuery(dataStrategy.Adapter, table.GetQualifiedName()).Where(criteria);
     //var data = dataStrategy.Find(table.GetQualifiedName(), criteria);
     //return CreateSimpleResultSet(table, dataStrategy, data);
 }
开发者ID:osaylan1,项目名称:Simple.Data,代码行数:7,代码来源:FindAllByCommand.cs

示例2: CreateDelegate

        public Func<object[], object> CreateDelegate(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
        {
            if (dataStrategy is SimpleTransaction) return null;

            var criteriaDictionary = CreateCriteriaDictionary(binder, args);
            if (criteriaDictionary == null) return null;

            var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), criteriaDictionary);
            try
            {
                var adapter = dataStrategy.GetAdapter();
                var func = adapter.OptimizingDelegateFactory.CreateFindOneDelegate(adapter, table.GetQualifiedName(), criteriaExpression);
                return a =>
                           {
                               var data = func(a);
                               return (data != null && data.Count > 0)
                                          ? new SimpleRecord(data, table.GetQualifiedName(), dataStrategy)
                                          : null;
                           };
            }
            catch (NotImplementedException)
            {
                return null;
            }
        }
开发者ID:hlach,项目名称:Simple.Data,代码行数:25,代码来源:FindByCommand.cs

示例3: CreateDelegate

        public Func<object[], object> CreateDelegate(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
        {
            if (dataStrategy is SimpleTransaction) return null;

            if (binder.Name.Equals("FindBy") || binder.Name.Equals("find_by"))
            {
                ArgumentHelper.CheckFindArgs(args, binder);
                if (args.Length == 1 && args[0].IsAnonymous()) return null;
            }

            var criteriaDictionary = ArgumentHelper.CreateCriteriaDictionary(binder, args, "FindBy", "find_by");
            if (criteriaDictionary == null) return null;

            var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), criteriaDictionary);
            try
            {
                var adapter = dataStrategy.GetAdapter();
                var func = adapter.OptimizingDelegateFactory.CreateFindOneDelegate(adapter, table.GetQualifiedName(), criteriaExpression);
                return a =>
                           {
                               var data = func(a);
                               return (data != null && data.Count > 0)
                                          ? new SimpleRecord(data, table.GetQualifiedName(), dataStrategy)
                                          : null;
                           };
            }
            catch (NotImplementedException)
            {
                return null;
            }
        }
开发者ID:JorgeGamba,项目名称:Simple.Data,代码行数:31,代码来源:FindByCommand.cs

示例4: CreateDelegate

        public Func<object[], object> CreateDelegate(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
        {
            if (dataStrategy is SimpleTransaction) return null;

            if (binder.Name.Equals("FindBy") || binder.Name.Equals("find_by"))
            {
                if (args.Length == 0) throw new ArgumentException("FindBy requires arguments.");
                if (args.Length == 1)
                {
                    if (ReferenceEquals(args[0], null)) throw new ArgumentException("FindBy does not accept unnamed null argument.");
                    if (args[0].GetType().Namespace == null) return null;
                }
            }

            var criteriaDictionary = CreateCriteriaDictionary(binder, args);
            if (criteriaDictionary == null) return null;

            var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), criteriaDictionary);
            try
            {
                var adapter = dataStrategy.GetAdapter();
                var func = adapter.OptimizingDelegateFactory.CreateFindOneDelegate(adapter, table.GetQualifiedName(), criteriaExpression);
                return a =>
                           {
                               var data = func(a);
                               return (data != null && data.Count > 0)
                                          ? new SimpleRecord(data, table.GetQualifiedName(), dataStrategy)
                                          : null;
                           };
            }
            catch (NotImplementedException)
            {
                return null;
            }
        }
开发者ID:kotsaris,项目名称:Simple.Data,代码行数:35,代码来源:FindByCommand.cs

示例5: InsertEntity

        private static object InsertEntity(object entity, DataStrategy dataStrategy, string tableName, ErrorCallback onError, bool resultRequired)
        {
            var dictionary = entity as IDictionary<string, object>;
            if (dictionary != null)
                return dataStrategy.Insert(tableName, dictionary, resultRequired);

            var list = entity as IEnumerable<IDictionary<string, object>>;
            if (list != null)
                return dataStrategy.InsertMany(tableName, list, onError, resultRequired);

            var entityList = entity as IEnumerable;
            if (entityList != null)
            {
                var array = entityList.Cast<object>().ToArray();
                var rows = new List<IDictionary<string, object>>();
                foreach (var o in array)
                {
                    dictionary = (o as IDictionary<string, object>) ?? o.ObjectToDictionary();
                    if (dictionary.Count == 0)
                    {
                        throw new SimpleDataException("Could not discover data in object.");
                    }
                    rows.Add(dictionary);
                }

                return dataStrategy.InsertMany(tableName, rows, onError, resultRequired);
            }

            dictionary = entity.ObjectToDictionary();
            if (dictionary.Count == 0)
                throw new SimpleDataException("Could not discover data in object.");
            return dataStrategy.Insert(tableName, dictionary, resultRequired);
        }
开发者ID:hlach,项目名称:Simple.Data,代码行数:33,代码来源:InsertCommand.cs

示例6: UpdateByKeyFields

 internal static object UpdateByKeyFields(string tableName, DataStrategy dataStrategy, object entity, IEnumerable<string> keyFieldNames)
 {
     var record = ObjectToDictionary(entity);
     var criteria = GetCriteria(keyFieldNames, record);
     var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(tableName, criteria);
     return dataStrategy.Update(tableName, record, criteriaExpression);
 }
开发者ID:ryansroberts,项目名称:Simple.Data,代码行数:7,代码来源:UpdateCommand.cs

示例7: ExecuteFunctionCommand

 public ExecuteFunctionCommand(DataStrategy database, IAdapterWithFunctions adapter, string functionName, IDictionary<string, object> arguments)
 {
     _database = database;
     _adapter = adapter;
     _functionName = functionName;
     _arguments = arguments;
 }
开发者ID:JorgeGamba,项目名称:Simple.Data,代码行数:7,代码来源:ExecuteFunctionCommand.cs

示例8: Execute

 public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
 {
     var result = dataStrategy.Run.Get(table.GetName(), args);
     if (result == null || result.Count == 0) return null;
     return binder.Name.Equals("get", StringComparison.OrdinalIgnoreCase)
                ? new SimpleRecord(result, table.GetQualifiedName(), dataStrategy)
                : result.First().Value;
 }
开发者ID:kotsaris,项目名称:Simple.Data,代码行数:8,代码来源:GetCommand.cs

示例9: DoInsert

 private static IDictionary<string, object> DoInsert(InvokeMemberBinder binder, object[] args, DataStrategy dataStrategy, string tableName)
 {
     return binder.HasSingleUnnamedArgument()
         ?
         InsertEntity(args[0], dataStrategy, tableName)
         :
         InsertDictionary(binder, args, dataStrategy, tableName);
 }
开发者ID:robashton,项目名称:Simple.Data,代码行数:8,代码来源:InsertCommand.cs

示例10: Execute

 public object Execute(DataStrategy dataStrategy, SimpleQuery query, InvokeMemberBinder binder, object[] args)
 {
     var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(query.TableName,
                                                                              CreateCriteriaDictionary(binder,
                                                                                                       args));
     query = query.Where(criteriaExpression).Take(1);
     return query.FirstOrDefault();
 }
开发者ID:hlach,项目名称:Simple.Data,代码行数:8,代码来源:FindByCommand.cs

示例11: Execute

 public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
 {
     var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(),
                                                                              CreateCriteriaDictionary(binder,
                                                                                                       args));
     var data = dataStrategy.Run.FindOne(table.GetQualifiedName(), criteriaExpression);
     return data != null ? new SimpleRecord(data, table.GetQualifiedName(), dataStrategy) : null;
 }
开发者ID:kotsaris,项目名称:Simple.Data,代码行数:8,代码来源:FindByCommand.cs

示例12: Execute

 public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
 {
     var criteria = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), MethodNameParser.ParseFromBinder(binder, args));
     var data = dataStrategy.Find(table.GetQualifiedName(), criteria);
     return new SimpleResultSet(data != null
                  ? data.Select(dict => new SimpleRecord(dict, table.GetQualifiedName(), dataStrategy))
                  : Enumerable.Empty<SimpleRecord>());
 }
开发者ID:Ang3lFir3,项目名称:Simple.Data,代码行数:8,代码来源:FindAllByCommand.cs

示例13: Execute

        /// <summary>
        /// Executes the command.
        /// </summary>
        /// <param name="dataStrategy">The data strategy.</param>
        /// <param name="table"></param>
        /// <param name="binder">The binder from the <see cref="DynamicTable"/> method invocation.</param>
        /// <param name="args">The arguments from the <see cref="DynamicTable"/> method invocation.</param>
        /// <returns></returns>
        public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
        {
            var criteriaDictionary = ArgumentHelper.CreateCriteriaDictionary(binder, args, "ExistsBy", "exists_by", "AnyBy", "any_by");
            if (criteriaDictionary == null) return null;

            var criteria  = ExpressionHelper.CriteriaDictionaryToExpression(table.GetQualifiedName(), criteriaDictionary);
            return new SimpleQuery(dataStrategy, table.GetQualifiedName()).Where(criteria).Exists();
        }
开发者ID:JorgeGamba,项目名称:Simple.Data,代码行数:16,代码来源:ExistsByCommand.cs

示例14: Execute

        /// <summary>
        /// Executes the command.
        /// </summary>
        /// <param name="dataStrategy">The database or transaction</param>
        /// <param name="table"></param>
        /// <param name="binder">The binder from the <see cref="DynamicTable"/> method invocation.</param>
        /// <param name="args">The arguments from the <see cref="DynamicTable"/> method invocation.</param>
        /// <returns></returns>
        public object Execute(DataStrategy dataStrategy, DynamicTable table, InvokeMemberBinder binder, object[] args)
        {
            if (args.Length == 1 && args[0] is SimpleExpression)
            {
                return new SimpleQuery(dataStrategy, table.GetQualifiedName()).Where((SimpleExpression)args[0]);
            }

            throw new BadExpressionException("FindAll only accepts a criteria expression.");
        }
开发者ID:JorgeGamba,项目名称:Simple.Data,代码行数:17,代码来源:FindAllCommand.cs

示例15: UpdateUsingKeys

        private static object UpdateUsingKeys(DataStrategy dataStrategy, DynamicTable table, object[] args)
        {
            var record = ObjectToDictionary(args[0]);
            var list = record as IList<IDictionary<string, object>>;
            if (list != null) return dataStrategy.UpdateMany(table.GetQualifiedName(), list);

            var dict = record as IDictionary<string, object>;
            return dataStrategy.Update(table.GetQualifiedName(), dict);
        }
开发者ID:reverentgeek,项目名称:Simple.Data,代码行数:9,代码来源:UpdateCommand.cs


注:本文中的DataStrategy类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。