本文整理汇总了C#中IEntityType.GetProperties方法的典型用法代码示例。如果您正苦于以下问题:C# IEntityType.GetProperties方法的具体用法?C# IEntityType.GetProperties怎么用?C# IEntityType.GetProperties使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEntityType
的用法示例。
在下文中一共展示了IEntityType.GetProperties方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConstructPropertyNameMap
private void ConstructPropertyNameMap(IEntityType entityType)
{
// use local propertyToPropertyNameMap to ensure no clashes in Property names
// within an EntityType but to allow them for properties in different EntityTypes.
// Also name of Property cannot be the same as the name of the enclosing EntityType.
var entityTypeName = new[] { _entityTypeToClassNameMap[entityType] };
var propertyToPropertyNameMap = new Dictionary<IProperty, string>();
foreach (var property in entityType.GetProperties())
{
var existingNames = propertyToPropertyNameMap.Values
.Concat(entityTypeName).ToList();
propertyToPropertyNameMap[property] =
CSharpUtilities.Instance.GenerateCSharpIdentifier(
_defaultPropertyNameFunc(property),
existingNames);
}
foreach (var keyValuePair in propertyToPropertyNameMap)
{
_propertyToPropertyNameMap.Add(keyValuePair.Key, keyValuePair.Value);
}
}
示例2: MapPropertiesToMembers
// TODO: Consider doing this at model building time, but also consider mapping to interfaces
// Issue #757
/// <summary>
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public virtual IEnumerable<Tuple<IProperty, MemberInfo>> MapPropertiesToMembers(IEntityType entityType)
{
var fieldCache = new Dictionary<Type, Dictionary<string, FieldInfo>>();
var propertyMappings = new List<Tuple<IProperty, MemberInfo>>();
foreach (var property in entityType.GetProperties().Where(p => !p.IsShadowProperty))
{
var propertyName = property.Name;
MemberInfo memberInfo = null;
foreach (var propertyInfo in entityType.ClrType.GetPropertiesInHierarchy(propertyName))
{
Debug.Assert(propertyInfo.DeclaringType != null);
// TODO: Handle cases where backing field is declared in a different class than the property
// Issue #758
Dictionary<string, FieldInfo> fields;
if (!fieldCache.TryGetValue(propertyInfo.DeclaringType, out fields))
{
fields = propertyInfo.DeclaringType.GetRuntimeFields().ToDictionary(f => f.Name);
fieldCache[propertyInfo.DeclaringType] = fields;
}
var fieldName = property["BackingField"] as string;
if (fieldName != null)
{
FieldInfo fieldInfo;
if (!fields.TryGetValue(fieldName, out fieldInfo))
{
throw new InvalidOperationException(CoreStrings.MissingBackingField(entityType.Name, propertyName, fieldName));
}
if (!fieldInfo.FieldType.GetTypeInfo().IsAssignableFrom(property.ClrType.GetTypeInfo()))
{
throw new InvalidOperationException(
CoreStrings.BadBackingFieldType(fieldName, fieldInfo.FieldType.Name, entityType.Name, propertyName, property.ClrType.Name));
}
memberInfo = fieldInfo;
}
else
{
memberInfo = _fieldMatcher.TryMatchFieldName(property, propertyInfo, fields);
}
if (memberInfo != null)
{
break;
}
}
if (memberInfo == null)
{
memberInfo = entityType.ClrType.GetPropertiesInHierarchy(propertyName).FirstOrDefault(p => p.SetMethod != null);
}
if (memberInfo == null)
{
throw new InvalidOperationException(CoreStrings.NoFieldOrSetter(entityType.Name, propertyName));
}
propertyMappings.Add(Tuple.Create(property, memberInfo));
}
return propertyMappings;
}
示例3: CreateEntityType
private static IEdmEntityType CreateEntityType(
IModel efModel, IEntityType efEntityType,
EdmModel model, out List<EdmStructuralProperty> concurrencyProperties)
{
// TODO GitHubIssue#36 : support complex and entity inheritance
var entityType = new EdmEntityType(
efEntityType.ClrType.Namespace, efEntityType.ClrType.Name);
concurrencyProperties = null;
foreach (var efProperty in efEntityType.GetProperties())
{
var type = ModelProducer.GetPrimitiveTypeReference(efProperty);
if (type != null)
{
string defaultValue = null;
if (efProperty.SqlServer().DefaultValue != null)
{
defaultValue = efProperty.SqlServer().DefaultValue.ToString();
}
var property = entityType.AddStructuralProperty(
efProperty.Name, type, defaultValue,
EdmConcurrencyMode.None); // alway None:replaced by OptimisticConcurrency annotation
// TODO GitHubIssue#57: Complete EF7 to EDM model mapping
if (efProperty.StoreGeneratedAlways)
{
SetComputedAnnotation(model, property);
}
if (efProperty.IsConcurrencyToken)
{
concurrencyProperties = concurrencyProperties ?? new List<EdmStructuralProperty>();
concurrencyProperties.Add(property);
}
}
}
var key = efEntityType.GetPrimaryKey();
if (key != null)
{
entityType.AddKeys(key.Properties
.Select(p => entityType.FindProperty(p.Name))
.Cast<IEdmStructuralProperty>());
}
return entityType;
}