5 // Copyright (c) 2007-2008 Jiri Moudry, Pascal Craponne
\r
7 // Permission is hereby granted, free of charge, to any person obtaining a copy
\r
8 // of this software and associated documentation files (the "Software"), to deal
\r
9 // in the Software without restriction, including without limitation the rights
\r
10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
11 // copies of the Software, and to permit persons to whom the Software is
\r
12 // furnished to do so, subject to the following conditions:
\r
14 // The above copyright notice and this permission notice shall be included in
\r
15 // all copies or substantial portions of the Software.
\r
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
28 using System.Xml.Serialization;
\r
29 using DbLinq.Vendor;
\r
31 namespace DbMetal.Schema
\r
34 /// This class main purpose is to allow renamings.
\r
35 /// It is based on DBML format (but simpler).
\r
37 //[XmlRoot("Database")]
\r
38 [XmlRoot("Database", Namespace = "http://schemas.microsoft.com/linqtosql/dbml/2007", IsNullable = false)]
\r
39 public class DbmlRename : INameAliases
\r
41 [XmlNamespaceDeclarations]
\r
42 public XmlSerializerNamespaces XmlNamespaceDeclarations { get; set; }
\r
44 [XmlAttribute("Name")]
\r
45 public string Name { get; set; }
\r
47 [XmlAttribute("Class")]
\r
48 public string Class { get; set; }
\r
50 [XmlElement("Table")]
\r
51 public Table[] Tables { get; set; }
\r
55 [XmlAttribute("Name")]
\r
56 public string Name { get; set; }
\r
58 [XmlAttribute("Member")]
\r
59 public string Member { get; set; }
\r
61 [XmlElement("Type")]
\r
62 public Type Type { get; set; }
\r
67 [XmlAttribute("Name")]
\r
68 public string Name { get; set; }
\r
70 [XmlElement("Column")]
\r
71 public Column[] Columns { get; set; }
\r
76 [XmlAttribute("Name")]
\r
77 public string Name { get; set; }
\r
79 [XmlAttribute("Member")]
\r
80 public string Member { get; set; }
\r
82 [XmlAttribute("Storage")]
\r
83 public string Storage { get; set; }
\r
85 [XmlAttribute("Type")]
\r
86 public string Type { get; set; }
\r
89 protected Table GetTable(string table, string schema)
\r
91 string qualifiedName;
\r
92 if (!string.IsNullOrEmpty(schema))
\r
93 qualifiedName = string.Format("{0}.{1}", schema, table);
\r
95 qualifiedName = table;
\r
96 return (from t in Tables where t.Name == qualifiedName select t).SingleOrDefault();
\r
99 protected Column GetColumn(string column, string table, string schema)
\r
101 var t = GetTable(table, schema);
\r
102 if (t == null || t.Type == null || t.Type.Columns == null)
\r
104 return (from c in t.Type.Columns where c.Name == column select c).SingleOrDefault();
\r
107 public string GetTableTypeAlias(string table, string schema)
\r
109 var t = GetTable(table, schema);
\r
110 if (t == null || t.Type == null)
\r
112 return t.Type.Name;
\r
115 public string GetTableMemberAlias(string table, string schema)
\r
117 var t = GetTable(table, schema);
\r
123 public string GetColumnMemberAlias(string column, string table, string schema)
\r
125 var c = GetColumn(column, table, schema);
\r
131 public string GetColumnForcedType(string column, string table, string schema)
\r
133 var c = GetColumn(column, table, schema);
\r
139 public string GetDatabaseNameAlias(string databaseName)
\r
144 public string GetClassNameAlias(string className)
\r