本文整理汇总了C#中Schema.Where方法的典型用法代码示例。如果您正苦于以下问题:C# Schema.Where方法的具体用法?C# Schema.Where怎么用?C# Schema.Where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Schema
的用法示例。
在下文中一共展示了Schema.Where方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Update
/// <summary>
/// Convert an Erlang hierarchical term representing a schema to a Row.
/// </summary>
/// <param name="row">Row to update</param>
/// <param name="data">
/// Data to update row with.
/// The data must be in the form {SchemaName::atom, [{FieldName::atom(), Value}]}.
/// </param>
/// <param name="schema">Alternative schema to use in place of row.Schema</param>
/// <param name="targetName">Name of the target for looking up field attributes</param>
/// <param name="schemaName">Alternative name of the top-most 'SchemaName' atom used in the "data".</param>
/// <param name="knownSchemas">List of known schemas to use when initializing a field a DynamicRow type.</param>
public static void Update(this Row row, IErlObject data, Schema schema = null, string targetName = null,
string schemaName = null, Registry<Schema> knownSchemas = null)
{
if (schema == null)
schema = row.Schema;
if (schemaName == null)
schemaName = schema.Name;
if (data == null)
data = new ErlTuple(new ErlAtom(schemaName), new ErlList());
// Input data must be in the form: {SchemaName::atom(), [{FieldName::atom(), Value}]}
// where Value can be any primitive value or a hierarchical value with another Row type.
if (!checkKeyValueTuple(data) || ((ErlTuple)data)[1].TypeOrder != ErlTypeOrder.ErlList)
throw new ErlDataAccessException(
StringConsts.ERL_DS_CRUD_RESP_SCH_MISMATCH_ERROR.Args(data.ToString(), schema.Name));
var dataList = ((ErlTuple)data)[1] as ErlList;
// Make sure that the first element of the tuple matches the schema name
if (!((ErlTuple)data)[0].ValueAsString.Equals(schemaName))
throw new ErlDataAccessException(
StringConsts.ERL_DS_CRUD_RESP_SCH_MISMATCH_ERROR.Args(data.ToString(), schema.Name));
// Contains a set of field names that are present in configuration
var presentFieldNames = new HashSet<string>();
foreach (var item in dataList.Where(checkKeyValueTuple).Cast<ErlTuple>())
presentFieldNames.Add(item[0].ValueAsString);
ErlList newList = null;
foreach (var fld in schema.Where(fd => typeof(Row).IsAssignableFrom(fd.Type)))
if (!presentFieldNames.Contains(fld.Name))
{
if (newList == null)
newList = (ErlList)dataList.Clone();
// Add: {FieldName::atom(), []}
newList.Add(new ErlTuple(new ErlAtom(fld.Name), new ErlList()));
}
// If no new items were added to the list use current list:
if (newList == null) newList = dataList;
foreach (var item in newList.Where(checkKeyValueTuple).Cast<ErlTuple>())
{
var name = item[0].ValueAsString;
var value = item[1];
var fdef = schema[name];
var attr = fdef[targetName];
if (!attr.Visible || (attr.Metadata != null && attr.Metadata.Navigate("$readonly|$read-only|$read_only").ValueAsBool()))
continue;
// If this field is defined in the schema as a Row type, then we need to descend into the
// value's hierarchical structure and treat it as a nested row
if (typeof(Row).IsAssignableFrom(fdef.Type))
{
// Get the row associated
Schema chldSch;
var chldRow = row[fdef.Order] as Row;
// If the row has a field of Row type initialized, use its Schema value.
if (chldRow != null)
chldSch = chldRow.Schema;
else
{
// Otherwise lookup the schema from the given registry
if (!knownSchemas.TryGetValue(name, out chldSch))
throw new ErlDataAccessException(
StringConsts.ERL_DS_SCHEMA_NOT_KNOWN_ERROR.Args(name, data.ToString()));
// Construct the field's value as dynmiac row of the looked up schema type
chldRow = new DynamicRow(chldSch);
chldRow.ApplyDefaultFieldValues();
row[fdef.Order] = chldRow;
}
if (value.TypeOrder != ErlTypeOrder.ErlList)
throw new ErlDataAccessException(
StringConsts.ERL_DS_SCHEMA_INVALID_VALUE_ERROR.Args(chldSch.Name, value));
// Recursively update the field's value from given data by using the field's schema:
chldRow.Update(item, chldSch, targetName, knownSchemas: knownSchemas);
}
else
{
// This is a primitive value type
var clr = SchemaMap.ErlToClrValue(value, schema, fdef, null, data);
//.........这里部分代码省略.........