public static EntitySchema GetSchema <TEntity>() { var entityType = typeof(TEntity); var attrs = entityType.GetCustomAttributes(typeof(TableAttribute), false); if (attrs == null || attrs.Length == 0) { return(null); } var entitySchema = new EntitySchema(); entitySchema.TableName = (attrs[0] as TableAttribute).Name ?? entityType.Name; foreach (var property in entityType.GetProperties()) { attrs = property.GetCustomAttributes(typeof(ColumnAttribute), false); if (attrs == null || attrs.Length == 0) { continue; } var attr = attrs[0] as ColumnAttribute; var columnSchema = new ColumnSchema(); columnSchema.PropertyName = property.Name; columnSchema.ColumnName = attr.Name ?? property.Name; columnSchema.DataType = attr.DataType; columnSchema.MaxLength = attr.MaxLength; columnSchema.IsRequired = attr.IsRequired; columnSchema.IsIdentity = attr.IsIdentity; columnSchema.DefaultValue = attr.DefaultValue; if (attr is PrimaryKeyAttribute) { columnSchema.IsPrimaryKey = true; } entitySchema.Columns.Add(columnSchema); } return(entitySchema); }
public PropertyBuilder Property <TProperty>(Expression <Func <TEntity, TProperty> > propertyExpression) { if (propertyExpression.Body.NodeType != ExpressionType.MemberAccess) { throw new NotSupportedException($"不支持的Lambda表达式:{propertyExpression}"); } var propertyName = (propertyExpression.Body as MemberExpression).Member.Name; var columnSchema = m_pSchema.Columns.FirstOrDefault(t => t.PropertyName == propertyName); if (columnSchema == null) { columnSchema = new ColumnSchema() { PropertyName = propertyName }; m_pSchema.Columns.Add(columnSchema); } return(new PropertyBuilder(columnSchema)); }
internal PropertyBuilder(ColumnSchema schema) { m_pSchema = schema; }
protected abstract IDataParameter CreateParameter(string name, ColumnSchema schema);