/// <summary> /// Creates a new instance of <see cref="ColumnPropertyDescriptor"/> from a <see cref="PropertyDecoration"/> instance. /// </summary> /// <remarks> /// If the property is not decorated with the <see cref="ColumnAttribute"/> the method will return <c>null</c>. /// </remarks> /// <param name="property">The property info to use.</param> /// <returns>A column property descriptor or null otherwise.</returns> internal static IColumnPropertyDescriptor Create(PropertyDecoration property) { if (property == null) { throw new ArgumentNullException(nameof(property), "The property collection can not be null."); } var descriptor = new ColumnPropertyDescriptor(property); return(descriptor.Initialize() ? descriptor : null); }
/// <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(); } }
/// <summary> /// Initializes the table type descriptor. /// </summary> private void Initialize() { var typeInfo = this.Type.GetTypeInfo(); this.AllProperties = ColumnPropertyDescriptor.Create(typeInfo.DeclaredProperties.Select(x => new PropertyDecoration(x, x.GetCustomAttributes().ToList()))); }