public ModelProperty NewPrimaryKey(ModelClass cls, Column column) { ModelProperty property = NewProperty(cls, column); property.KeyType = KeyType.PrimaryKey; return property; }
public ModelProperty NewCompositeKey(ModelClass cls, Column column, string compositeKeyName) { ModelProperty property = NewProperty(cls, column); property.KeyType = KeyType.CompositeKey; property.CompositeKeyName = compositeKeyName; return property; }
public ModelProperty NewProperty(ModelClass cls, Column column) { ModelProperty property = new ModelProperty(_store); property.Name = ModelHelper.GetSafeName(column.Name, _model.PropertyNameFilterExpression); property.Column = column.Name; property.NotNull = !column.Nullable; property.Accessor = Accessor.Public; property.ModelClass = cls; return property; }
public List<Column> GetProperties(ModelClass cls) { List<Column> list = new List<Column>(); IDbCommand command = GetColumnCommand(cls.Table, cls.Schema); using (IDataReader reader = command.ExecuteReader()) { while (reader.Read()) { Column column; column = list.Find(delegate(Column col) { return col.Name == reader["COLUMN_NAME"].ToString(); } ); if (column == null) { column = new Column(); column.Name = reader["COLUMN_NAME"].ToString(); column.Schema = cls.Schema; column.Table = cls.Table; column.DataType = reader["DATA_TYPE"].ToString(); if (column.DataType == "NUMBER") { string scale = reader["DATA_SCALE"].ToString(); if (scale == "0" || string.IsNullOrEmpty(scale)) { column.DataType = "INTEGER"; // If field is primary key and "integer" it is reasonably safe to assume that it is has // a sequence behind it. Confirming that would in Oracle require trigger parsing column.Identity = reader["PKEY"] != DBNull.Value ? true : false; } } if (reader["PKEY"] != DBNull.Value) { column.Primary = true; column.PrimaryConstraintName = reader["PKEY"].ToString(); } if (reader["FKEY"] != DBNull.Value) { column.ForeignConstraints.Add(reader["FKEY"].ToString()); } column.Nullable = reader["NULLABLE"].ToString() == "N" ? false : true; list.Add(column); } } } return list; }
public List<Column> GetProperties(ModelClass cls) { List<Column> list = new List<Column>(); IDbCommand command = GetColumnCommand(cls.Table, cls.Schema); using(IDataReader reader = command.ExecuteReader()) { while(reader.Read()) { Column column; column = list.Find(delegate(Column col) { return col.Name == reader["COLUMN_NAME"].ToString(); } ); if (column == null) { column = new Column(); column.Name = reader["COLUMN_NAME"].ToString(); column.Schema = cls.Schema; column.Table = cls.Table; column.DataType = reader["DATA_TYPE"].ToString(); if (reader["CONSTRAINT_TYPE"] != DBNull.Value) { switch(reader["CONSTRAINT_TYPE"].ToString()) { case "PRIMARY KEY": column.Primary = true; column.PrimaryConstraintName = reader["CONSTRAINT_NAME"].ToString(); break; case "FOREIGN KEY": column.ForeignConstraints.Add(reader["CONSTRAINT_NAME"].ToString()); break; // Check constraints not supported right now. } } column.Nullable = reader["IS_NULLABLE"].ToString() == "NO" ? false : true; column.Identity = reader["IS_IDENTITY"].ToString() == "1" ? true : false; list.Add(column); } } } return list; }
public static Relation GetForeginColumn(List<Relation> relations, Column key) { return relations.Find( delegate(Relation rel) { return (rel.ForeignOwner == key.Schema && rel.ForeignTable == key.Table && rel.ForeignColumn == key.Name); } ); }