protected virtual object CreateId(IColumnMetadata[] keyColumns,ITableMetadata tableMetadata) { if (keyColumns.Length == 1) { var id = new id(); id.generator = GetGenerator(keyColumns[0],tableMetadata); id.type1 = typeConverter.GetNHType(keyColumns[0]); id.name = currentContext.NamingStrategy.GetIdPropertyNameFromColumnName(keyColumns[0].Name); id.column1 = 0 == string.Compare(id.name, keyColumns[0].Name, true) ? null : keyColumns[0].Name;// keyColumns[0].Name; return id; } else if (keyColumns.Length > 1) { var cid = new compositeid(); string entityName = currentContext.NamingStrategy.GetEntityNameFromTableName(tableMetadata.Name); cid.@class = currentContext.NamingStrategy.GetClassNameForComponentKey(entityName); List<keyproperty> keyps = new List<keyproperty>(); cid.name = currentContext.NamingStrategy.GetNameForComponentKey(entityName,cid.@class); foreach (IColumnMetadata meta in keyColumns) { keyproperty kp = new keyproperty(); kp.name = currentContext.NamingStrategy.GetPropertyNameFromColumnName(meta.Name); kp.column1 = 0 == string.Compare(kp.name, meta.Name, true) ? null : meta.Name; kp.length = meta.ColumnSize != 0 ? meta.ColumnSize.ToString() : null; kp.type1 = typeConverter.GetNHType(meta); keyps.Add(kp); } cid.Items = keyps.ToArray(); return cid; } return null; }
protected virtual object CreateId(IColumnMetadata[] keyColumns, ITableMetadata tableMetadata) { if (keyColumns.Length == 1) { var id = new id(); id.generator = GetGenerator(keyColumns[0], tableMetadata); id.type1 = typeConverter.GetNHType(keyColumns[0]); id.name = currentContext.NamingStrategy.GetIdPropertyNameFromColumnName(keyColumns[0].Name); id.column1 = 0 == string.Compare(id.name, keyColumns[0].Name, true) ? null : keyColumns[0].Name;// keyColumns[0].Name; return(id); } else if (keyColumns.Length > 1) { var cid = new compositeid(); string entityName = currentContext.NamingStrategy.GetEntityNameFromTableName(tableMetadata.Name); cid.@class = currentContext.NamingStrategy.GetClassNameForComponentKey(entityName); List <keyproperty> keyps = new List <keyproperty>(); cid.name = currentContext.NamingStrategy.GetNameForComponentKey(entityName, cid.@class); foreach (IColumnMetadata meta in keyColumns) { keyproperty kp = new keyproperty(); kp.name = currentContext.NamingStrategy.GetPropertyNameFromColumnName(meta.Name); kp.column1 = 0 == string.Compare(kp.name, meta.Name, true) ? null : meta.Name; kp.length = meta.ColumnSize != 0 ? meta.ColumnSize.ToString() : null; kp.type1 = typeConverter.GetNHType(meta); keyps.Add(kp); } cid.Items = keyps.ToArray(); return(cid); } return(null); }
public static void AddKeyProperty(this compositeid theCompositeId, keyproperty keyProperty) { if (theCompositeId.Items == null) { theCompositeId.Items = new object[0]; } object[] items = theCompositeId.Items; Array.Resize(ref items, theCompositeId.Items.Length + 1); items[items.Length - 1] = keyProperty; theCompositeId.Items = items; }
private void ProcessEntityKey(Entity entity, @class newClass, ITable table) { // We do nothing with EntityKeyType.Empty, as there is nothing to do. if (entity.Key.KeyType == EntityKeyType.Properties) { ProcessPropertyEntityKey(entity, newClass, table); } else if (entity.Key.KeyType == EntityKeyType.Component) { compositeid cId = GetCompositeIDWithComponent(entity.Key.Component); newClass.SetCompositeId(cId); } }
/// <summary> /// Gets a collection of KeyProperties in the CompositeId /// </summary> /// <param name="theCompositeId"></param> /// <returns></returns> public static IEnumerable <keyproperty> KeyProperties(this compositeid theCompositeId) { if (theCompositeId.Items == null) { yield break; } foreach (var item in theCompositeId.Items) { if (item is keyproperty) { yield return(item as keyproperty); } } }
private void ProcessPropertyEntityKey(Entity entity, @class newClass, ITable table) { var keyProperties = entity.Key.Properties; bool isSingleColumnPK = keyProperties.Count() == 1; if (isSingleColumnPK) { id newClassId = SetupSingleColumnPrimaryKey(entity); newClass.SetId(newClassId); } else { compositeid cId = GetCompositeIDWithProperties(table, entity); newClass.SetCompositeId(cId); } }
private static compositeid GetCompositeIDWithProperties(ITable table, Entity entity) { compositeid cId = new compositeid(); foreach (var property in entity.Key.Properties) { IColumn mappedColumn = property.MappedColumn(); if (mappedColumn == null) { continue; } cId.AddKeyProperty(new keyproperty { column1 = mappedColumn.Name.BackTick(), name = property.Name }); } return(cId); }
private static compositeid GetCompositeIDWithComponent(Component component) { compositeid cId = new compositeid(); cId.@class = component.Specification.Name; cId.name = component.Name; foreach (var property in component.Properties) { IColumn mappedColumn = property.MappedColumn(); if (mappedColumn == null) { continue; } cId.AddKeyProperty(new keyproperty { column1 = mappedColumn.Name.BackTick(), name = property.PropertyName }); } return(cId); }