示例#1
0
        /// <summary>
        /// Returns mapped entity descriptor
        /// </summary>
        /// <param name="entityType">Type of entity</param>
        /// <returns>Mapped entity descriptor</returns>
        public virtual NopEntityDescriptor GetEntityDescriptor(Type entityType)
        {
            return(EntityDescriptors.GetOrAdd(entityType, t =>
            {
                var tableName = NameCompatibilityManager.GetTableName(t);
                var expression = new CreateTableExpression {
                    TableName = tableName
                };
                var builder = new CreateTableExpressionBuilder(expression, new NullMigrationContext());
                builder.RetrieveTableExpressions(t);

                return new NopEntityDescriptor
                {
                    EntityName = tableName,
                    Fields = builder.Expression.Columns.Select(column => new NopEntityFieldDescriptor
                    {
                        Name = column.Name,
                        IsPrimaryKey = column.IsPrimaryKey,
                        IsNullable = column.IsNullable,
                        Size = column.Size,
                        Precision = column.Precision,
                        IsIdentity = column.IsIdentity,
                        Type = getPropertyTypeByColumnName(t, column.Name)
                    }).ToList()
                };
            }));