private static MatchLevel Compare(Type thisSideType, Association thisSide, Type otherSideType, Association otherSide) { MatchLevel noMatch = MatchLevel.NoMatch; if (((thisSide.IsForeignKey == true) && (otherSide.IsForeignKey != true)) || ((thisSide.IsForeignKey != true) && (otherSide.IsForeignKey == true))) { noMatch = noMatch; } if (thisSideType.Name == otherSide.Type) { noMatch |= MatchLevel.ThisTypeAgrees; } if (otherSideType.Name == thisSide.Type) { noMatch |= MatchLevel.OtherTypeAgrees; } if (BuildKeyField(thisSide.GetOtherKey()) == BuildKeyField(otherSide.GetThisKey())) { noMatch |= MatchLevel.ThisOtherKeyMatchesOtherThisKey; } if (BuildKeyField(thisSide.GetThisKey()) == BuildKeyField(otherSide.GetOtherKey())) { noMatch |= MatchLevel.ThisThisKeyMatchisOtherOtherKey; } return noMatch; }
private static void NullifyUpdateCheckOfColumns(Type type) { bool isVersion = false; foreach (Column column in type.Columns) { if (column.IsVersion == true) { isVersion = true; break; } } if (isVersion) { foreach (Column column in type.Columns) if (column.UpdateCheck.HasValue && column.UpdateCheck.Value == UpdateCheck.Never) column.UpdateCheck = null; } else { foreach (Column column in type.Columns) { if (column.IsReadOnly == true) { if (column.UpdateCheck.HasValue && column.UpdateCheck.Value == UpdateCheck.Never) column.UpdateCheck = null; } else if (column.UpdateCheck.HasValue && column.UpdateCheck.Value == UpdateCheck.Always) { column.UpdateCheck = null; } } } }
public override Type VisitType(Type type) { if (currentTable != null) { typeToTable[type.Name] = currentTable; } return base.VisitType(type); }
public static string[] GetPrimaryKeys(Type type) { var list = new List<string>(); foreach (Column column in type.Columns) { if (column.IsPrimaryKey == true) { list.Add(column.Name); } } return list.ToArray(); }
private void CreateResult(Function function, CommandResultSchema commandResultSchema, string defaultName, int index) { string name = defaultName; Type result; if (function.Types.Contains(name)) { result = function.Types[name]; } else if (function.Types.Count >= index + 1) { result = function.Types[index]; } else { result = new Type(ToClassName(name)); function.Types.Add(result); } if (result.IsProcessed) { return; } // ElementType/@Name safe attribute if (string.IsNullOrEmpty(result.Name)) { result.Name = ToClassName(name); } foreach (CommandResultColumnSchema c in commandResultSchema.Columns) { Column column; if (result.Columns.Contains(c.Name)) { column = result.Columns[c.Name]; } else { column = new Column(GetSystemType(c)); column.Name = c.Name; result.Columns.Add(column); } if (!column.IsProcessed) { PopulateColumn(column, c, result.Name); } } result.IsProcessed = true; }
public Table(string name, Type type) { if (name == null) { throw Error.SchemaRequirementViolation("Table", "Name"); } this.name = name; if (type == null) { throw Error.SchemaRequirementViolation("Table", "Type"); } this.type = type; }
public override Type VisitType(Type type) { Type t; if (dbTypes.TryGetValue(type.Name, out t)) { if (t != type) throw Error.Bug(" (" + message + "): Type with name " + type.Name + " has multiple Type instances in DBML."); } else dbTypes.Add(type.Name, type); return base.VisitType(type); }
private Table CreateTable(TableSchema tableSchema) { Type type = new Type(ToClassName(tableSchema.Name)); Table t = new Table(tableSchema.FullName, type); t.Member = t.Type.Name; if (Array.BinarySearch(ExistingContextProperties, t.Type.Name) >= 1) { t.Member += "Table"; } Database.Tables.Add(t); return(t); }
private void CreateView(ViewSchema viewSchema) { Table table; if (Database.Tables.Contains(viewSchema.FullName)) { table = Database.Tables[viewSchema.FullName]; } else { Type type = new Type(ToClassName(viewSchema.Name)); table = new Table(viewSchema.FullName, type); Database.Tables.Add(table); } if (string.IsNullOrEmpty(table.Type.Name)) { table.Type.Name = ToClassName(viewSchema.Name); } if (string.IsNullOrEmpty(table.Member)) { table.Member = table.Type.Name; } foreach (ViewColumnSchema columnSchema in viewSchema.Columns) { Column column; if (table.Type.Columns.Contains(columnSchema.Name)) { column = table.Type.Columns[columnSchema.Name]; } else { column = new Column(GetSystemType(columnSchema)); column.Name = columnSchema.Name; table.Type.Columns.Add(column); } PopulateColumn(column, columnSchema, table.Type.Name); } table.Type.Columns.IsProcessed = true; table.Type.Associations.IsProcessed = true; table.IsProcessed = true; }
public override Type VisitType(Type type) { if (type == null) return null; if (!type.IsInheritanceDefault.HasValue) type.IsInheritanceDefault = false; if (!type.AccessModifier.HasValue) type.AccessModifier = 0; bool isVersion = false; foreach (Column column in type.Columns) { if (column.IsVersion == true) { isVersion = true; break; } } if (isVersion) { foreach (Column column in type.Columns) if (!column.UpdateCheck.HasValue) column.UpdateCheck = (UpdateCheck) 1; } else { foreach (Column column in type.Columns) if (!column.UpdateCheck.HasValue) column.UpdateCheck = 0; } foreach (Column column in type.Columns) VisitColumn(column); foreach (Association association in type.Associations) VisitAssociation(association); foreach (Type subType in type.SubTypes) VisitType(subType); return type; }
private void CreateView(ViewSchema viewSchema) { Table table; if (Database.Tables.Contains(viewSchema.FullName)) { table = Database.Tables[viewSchema.FullName]; } else { Type type = new Type(ToClassName(viewSchema.Name)); table = new Table(viewSchema.FullName, type); Database.Tables.Add(table); } if (string.IsNullOrEmpty(table.Type.Name)) table.Type.Name = ToClassName(viewSchema.Name); if (string.IsNullOrEmpty(table.Member)) table.Member = table.Type.Name; foreach (ViewColumnSchema columnSchema in viewSchema.Columns) { Column column; if (table.Type.Columns.Contains(columnSchema.Name)) { column = table.Type.Columns[columnSchema.Name]; } else { column = new Column(GetSystemType(columnSchema)); column.Name = columnSchema.Name; table.Type.Columns.Add(column); } PopulateColumn(column, columnSchema, table.Type.Name); } table.Type.Columns.IsProcessed = true; table.Type.Associations.IsProcessed = true; table.IsProcessed = true; }
private Table CreateTable(TableSchema tableSchema) { Type type = new Type(ToClassName(tableSchema.Name)); Table t = new Table(tableSchema.FullName, type); t.Member = t.Type.Name; if (Array.BinarySearch(ExistingContextProperties, t.Type.Name) >= 1) t.Member += "Table"; Database.Tables.Add(t); return t; }
private void CreateResult(Function function, CommandResultSchema commandResultSchema, string defaultName, int index) { string name = defaultName; Type result; if (function.Types.Contains(name)) { result = function.Types[name]; } else if (function.Types.Count >= index + 1) { result = function.Types[index]; } else { result = new Type(ToClassName(name)); function.Types.Add(result); } if (result.IsProcessed) return; // ElementType/@Name safe attribute if (string.IsNullOrEmpty(result.Name)) result.Name = ToClassName(name); foreach (CommandResultColumnSchema c in commandResultSchema.Columns) { Column column; if (result.Columns.Contains(c.Name)) { column = result.Columns[c.Name]; } else { column = new Column(GetSystemType(c)); column.Name = c.Name; result.Columns.Add(column); } if (!column.IsProcessed) PopulateColumn(column, c, result.Name); } result.IsProcessed = true; }
public override Type VisitType(Type type) { if (type == null) return type; if (typeIds.ContainsKey(type)) { if (typeIds[type] == null) { typeIds[type] = "ID" + currentTypeId.ToString(CultureInfo.InvariantCulture); currentTypeId++; } } else typeIds.Add(type, null); return base.VisitType(type); }
public override Type VisitType(Type type) { string localName = ""; if (isFunctionElementType && !isSubType) localName = "ElementType"; else localName = "Type"; if (type == null) return null; if ((typeIds[type] != null) && pocessedTypes.Contains(type)) { string str2 = typeIds[type]; writer.WriteStartElement(localName); writer.WriteAttributeString("IdRef", str2); } else { pocessedTypes.Add(type); writer.WriteStartElement(localName); if (type.Name != null) writer.WriteAttributeString("Name", type.Name); if (typeIds[type] != null) writer.WriteAttributeString("Id", typeIds[type]); if (type.InheritanceCode != null) writer.WriteAttributeString("InheritanceCode", type.InheritanceCode); if (type.IsInheritanceDefault.HasValue) writer.WriteAttributeString("IsInheritanceDefault", ToXmlBooleanString(type.IsInheritanceDefault)); if (type.AccessModifier.HasValue) writer.WriteAttributeString("AccessModifier", type.AccessModifier.ToString()); if (type.Modifier.HasValue) writer.WriteAttributeString("Modifier", type.Modifier.ToString()); bool subType = isSubType; isSubType = true; base.VisitType(type); isSubType = subType; } writer.WriteEndElement(); return type; }
public static bool HasPrimaryKey(Type type) { foreach (Column column in type.Columns) { if (column.IsPrimaryKey == true) { return true; } } return false; }
public override Type VisitType(Type type) { if (type == null) return null; if (type.IsInheritanceDefault == false) type.IsInheritanceDefault = null; if (type.AccessModifier.HasValue && type.AccessModifier.Value == AccessModifier.Public) type.AccessModifier = null; NullifyUpdateCheckOfColumns(type); return base.VisitType(type); }
public static bool IsPrimaryKeyOfType(Type type, string[] columns) { int found = 0; int keyCount = 0; foreach (Column column in type.Columns) { if (column.IsPrimaryKey != true) { continue; } keyCount++; foreach (string str in columns) { if (column.Name == str) { found++; break; } } if (keyCount != found) { return false; } } return (columns.Length == found); }
public override Type VisitType(Type type) { Type type3; Type type2 = type; try { currentType = type; if (seen.ContainsKey(type)) { return type; } seen.Add(type, true); type3 = base.VisitType(type); } finally { currentType = type2; } return type3; }