コード例 #1
0
        /// <summary>
        /// Initializes the table type descriptor.
        /// </summary>
        private void Initialize()
        {
            var typeInfo  = this.Type.GetTypeInfo();
            var tableType = typeInfo.GetCustomAttribute <TableTypeAttribute>()?.Type ?? this.Type;

            if (tableType != this.Type)
            {
                typeInfo = tableType.GetTypeInfo();
            }

            var tableAttribute = typeInfo.GetCustomAttribute <TableAttribute>();

            if (tableAttribute == null)
            {
                throw new OrmMissingTableMappingException($"The type '{this.Type.Name}' does not have table mapping information.");
            }

            this.TypeName    = this.Type.Name;
            this.CatalogName = tableAttribute.Catalog;
            this.SchemaName  = tableAttribute.Schema;
            this.TableName   = tableAttribute.Name ?? tableType.Name;

            var properties = this.GetProperties(this.Type, tableType);

            this.AllProperties        = ColumnPropertyDescriptor.Create(properties);
            this.NavigationProperties = NavigationPropertyDescriptor.Create(this, properties);

            foreach (var property in this.AllProperties)
            {
                if (property.IsPrimaryKey)
                {
                    this.PrimaryKeyProperties.Add(property);
                }

                if (property.IsIdentity)
                {
                    this.IdentityProperty = property;
                }
                else
                {
                    this.SimpleProperties.Add(property);
                }
            }

            if (this.PrimaryKeyProperties.Any())
            {
                this.DefaultPrimaryKeyValues = this.PrimaryKeyProperties.Select(x => x.PropertyType.GetDefaultValue()).ToList();
            }
        }
コード例 #2
0
        /// <summary>
        /// Creates a new instance of <see cref="NavigationPropertyDescriptor"/> from a <see cref="PropertyDecoration"/> instance and a <see cref="TableTypeDescriptor"/>.
        /// </summary>
        /// <remarks>
        /// If the property is not decorated with the <see cref="NavigationAttribute"/> the method will return <c>null</c>.
        /// </remarks>
        /// <param name="fromDescriptor">The table type descriptor of the source property.</param>
        /// <param name="property">The property info to use.</param>
        /// <returns>A column property descriptor or null otherwise.</returns>
        internal static INavigationPropertyDescriptor Create(ITableTypeDescriptor fromDescriptor, PropertyDecoration property)
        {
            var descriptor = new NavigationPropertyDescriptor(fromDescriptor, property);

            return(descriptor.Initialize() ? descriptor : null);
        }