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


C# IEntityType.GetProperties方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:rbenhassine2,项目名称:EntityFramework,代码行数:22,代码来源:MetadataModelNameMapper.cs

示例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;
        }
开发者ID:RickyLin,项目名称:EntityFramework,代码行数:69,代码来源:MemberMapper.cs

示例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;
        }
开发者ID:adestis-mh,项目名称:RESTier,代码行数:47,代码来源:ModelProducer.cs


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