本文整理汇总了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);
}
示例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;
}
}
示例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;
}
}
示例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;
}
}
示例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);
}
示例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);
}
示例7: ExecuteFunctionCommand
public ExecuteFunctionCommand(DataStrategy database, IAdapterWithFunctions adapter, string functionName, IDictionary<string, object> arguments)
{
_database = database;
_adapter = adapter;
_functionName = functionName;
_arguments = arguments;
}
示例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;
}
示例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);
}
示例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();
}
示例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;
}
示例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>());
}
示例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();
}
示例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.");
}
示例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);
}