ad95e0103f8078267b93a943134dc02ec6238d25
[mono.git] / mcs / class / referencesource / System.Data.Entity.Design / System / Data / Entity / Design / SSDLGenerator / TableDetailsRow.cs
1 //---------------------------------------------------------------------
2 // <copyright file="TableDetailsRow.cs" company="Microsoft">
3 //      Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //
6 // @owner       Microsoft
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
9 using System.Collections.Generic;
10 using System.Xml;
11 using System.Data.Entity.Design.Common;
12 using System.Globalization;
13 using System.Data;
14
15 namespace System.Data.Entity.Design.SsdlGenerator
16 {
17     /// <summary>
18     /// Strongly typed DataTable for TableDetails
19     /// </summary>
20     internal sealed class TableDetailsRow : System.Data.DataRow
21     {
22
23         private TableDetailsCollection _tableTableDetails;
24
25         [System.Diagnostics.DebuggerNonUserCodeAttribute()]
26         internal TableDetailsRow(System.Data.DataRowBuilder rb)
27             :
28                 base(rb)
29         {
30             this._tableTableDetails = ((TableDetailsCollection)(base.Table));
31         }
32
33         /// <summary>
34         /// Gets a strongly typed table
35         /// </summary>
36         public new TableDetailsCollection Table
37         {
38             get
39             {
40                 return _tableTableDetails;
41             }
42         }
43
44         /// <summary>
45         /// Gets the Catalog column value
46         /// </summary>
47         public string Catalog
48         {
49             get
50             {
51                 try
52                 {
53                     return ((string)(this[this._tableTableDetails.CatalogColumn]));
54                 }
55                 catch (System.InvalidCastException e)
56                 {
57                     throw EDesignUtil.StonglyTypedAccessToNullValue(_tableTableDetails.CatalogColumn.ColumnName, _tableTableDetails.TableName, e);
58                 }
59             }
60             set
61             {
62                 this[this._tableTableDetails.CatalogColumn] = value;
63             }
64         }
65
66         /// <summary>
67         /// Gets the Schema column value
68         /// </summary>
69         public string Schema
70         {
71             get
72             {
73                 try
74                 {
75                     return ((string)(this[this._tableTableDetails.SchemaColumn]));
76                 }
77                 catch (System.InvalidCastException e)
78                 {
79                     throw EDesignUtil.StonglyTypedAccessToNullValue(_tableTableDetails.SchemaColumn.ColumnName, _tableTableDetails.TableName, e);
80                 }
81             }
82             set
83             {
84                 this[this._tableTableDetails.SchemaColumn] = value;
85             }
86         }
87
88         /// <summary>
89         /// Gets the TableName column value
90         /// </summary>
91         public string TableName
92         {
93             get
94             {
95                 try
96                 {
97                     return ((string)(this[this._tableTableDetails.TableNameColumn]));
98                 }
99                 catch (System.InvalidCastException e)
100                 {
101                     throw EDesignUtil.StonglyTypedAccessToNullValue(_tableTableDetails.TableNameColumn.ColumnName, _tableTableDetails.TableName, e);
102                 }
103             }
104             set
105             {
106                 this[this._tableTableDetails.TableNameColumn] = value;
107             }
108         }
109
110         /// <summary>
111         /// Gets the ColumnName column value
112         /// </summary>
113         public string ColumnName
114         {
115             get
116             {
117                 try
118                 {
119                     return ((string)(this[this._tableTableDetails.ColumnNameColumn]));
120                 }
121                 catch (System.InvalidCastException e)
122                 {
123                     throw EDesignUtil.StonglyTypedAccessToNullValue(_tableTableDetails.ColumnNameColumn.ColumnName, _tableTableDetails.TableName, e);
124                 }
125             }
126             set
127             {
128                 this[this._tableTableDetails.ColumnNameColumn] = value;
129             }
130         } 
131
132         /// <summary>
133         /// Gets the IsNullable column value
134         /// </summary>
135         public bool IsNullable
136         {
137             get
138             {
139                 try
140                 {
141                     return ((bool)(this[this._tableTableDetails.IsNullableColumn]));
142                 }
143                 catch (System.InvalidCastException e)
144                 {
145                     throw EDesignUtil.StonglyTypedAccessToNullValue(_tableTableDetails.IsNullableColumn.ColumnName, _tableTableDetails.TableName, e);
146                 }
147             }
148             set
149             {
150                 this[this._tableTableDetails.IsNullableColumn] = value;
151             }
152         }
153
154         /// <summary>
155         /// Gets the DataType column value
156         /// </summary>
157         public string DataType
158         {
159             get
160             {
161                 try
162                 {
163                     return ((string)(this[this._tableTableDetails.DataTypeColumn]));
164                 }
165                 catch (System.InvalidCastException e)
166                 {
167                     throw EDesignUtil.StonglyTypedAccessToNullValue(_tableTableDetails.DataTypeColumn.ColumnName, _tableTableDetails.TableName, e);
168                 }
169             }
170             set
171             {
172                 this[this._tableTableDetails.DataTypeColumn] = value;
173             }
174         }
175
176         /// <summary>
177         /// Gets the MaximumLength column value
178         /// </summary>
179         public int MaximumLength
180         {
181             get
182             {
183                 try
184                 {
185                     return ((int)(this[this._tableTableDetails.MaximumLengthColumn]));
186                 }
187                 catch (System.InvalidCastException e)
188                 {
189                     throw EDesignUtil.StonglyTypedAccessToNullValue(_tableTableDetails.MaximumLengthColumn.ColumnName, _tableTableDetails.TableName, e);
190                 }
191             }
192             set
193             {
194                 this[this._tableTableDetails.MaximumLengthColumn] = value;
195             }
196         }
197
198         /// <summary>
199         /// Gets the DateTime Precision column value
200         /// </summary>
201         public int DateTimePrecision
202         {
203             get
204             {
205                 try
206                 {
207                     return ((int)(this[this._tableTableDetails.DateTimePrecisionColumn]));
208                 }
209                 catch (System.InvalidCastException e)
210                 {
211                     throw EDesignUtil.StonglyTypedAccessToNullValue(_tableTableDetails.DateTimePrecisionColumn.ColumnName, _tableTableDetails.TableName, e);
212                 }
213             }
214             set
215             {
216                 this[this._tableTableDetails.DateTimePrecisionColumn] = value;
217             }
218         }
219
220
221         /// <summary>
222         /// Gets the Precision column value
223         /// </summary>
224         public int Precision
225         {
226             get
227             {
228                 try
229                 {
230                     return ((int)(this[this._tableTableDetails.PrecisionColumn]));
231                 }
232                 catch (System.InvalidCastException e)
233                 {
234                     throw EDesignUtil.StonglyTypedAccessToNullValue(_tableTableDetails.PrecisionColumn.ColumnName, _tableTableDetails.TableName, e);
235                 }
236             }
237             set
238             {
239                 this[this._tableTableDetails.PrecisionColumn] = value;
240             }
241         }
242
243         /// <summary>
244         /// Gets the Scale column value
245         /// </summary>
246         public int Scale
247         {
248             get
249             {
250                 try
251                 {
252                     return ((int)(this[this._tableTableDetails.ScaleColumn]));
253                 }
254                 catch (System.InvalidCastException e)
255                 {
256                     throw EDesignUtil.StonglyTypedAccessToNullValue(_tableTableDetails.ScaleColumn.ColumnName, _tableTableDetails.TableName, e);
257                 }
258             }
259             set
260             {
261                 this[this._tableTableDetails.ScaleColumn] = value;
262             }
263         }
264
265         /// <summary>
266         /// Gets the IsServerGenerated column value
267         /// </summary>
268         public bool IsIdentity
269         {
270             get
271             {
272                 try
273                 {
274                     return ((bool)(this[this._tableTableDetails.IsIdentityColumn]));
275                 }
276                 catch (System.InvalidCastException e)
277                 {
278                     throw EDesignUtil.StonglyTypedAccessToNullValue(_tableTableDetails.IsIdentityColumn.ColumnName, _tableTableDetails.TableName, e);
279                 }
280             }
281             set
282             {
283                 this[this._tableTableDetails.IsIdentityColumn] = value;
284             }
285         }
286
287         /// <summary>
288         /// Gets the IsServerGenerated column value
289         /// </summary>
290         public bool IsServerGenerated
291         {
292             get
293             {
294                 try
295                 {
296                     return ((bool)(this[this._tableTableDetails.IsServerGeneratedColumn]));
297                 }
298                 catch (System.InvalidCastException e)
299                 {
300                     throw EDesignUtil.StonglyTypedAccessToNullValue(_tableTableDetails.IsServerGeneratedColumn.ColumnName, _tableTableDetails.TableName, e);
301                 }
302             }
303             set
304             {
305                 this[this._tableTableDetails.IsServerGeneratedColumn] = value;
306             }
307         }
308
309         /// <summary>
310         /// Gets the IsPrimaryKey column value
311         /// </summary>
312         public bool IsPrimaryKey
313         {
314             get
315             {
316                 try
317                 {
318                     return ((bool)(this[this._tableTableDetails.IsPrimaryKeyColumn]));
319                 }
320                 catch (System.InvalidCastException e)
321                 {
322                     throw EDesignUtil.StonglyTypedAccessToNullValue(_tableTableDetails.IsPrimaryKeyColumn.ColumnName, _tableTableDetails.TableName, e);
323                 }
324             }
325             set
326             {
327                 this[this._tableTableDetails.IsPrimaryKeyColumn] = value;
328             }
329         }
330
331         /// <summary>
332         /// Determines if the Catalog column value is null
333         /// </summary>
334         /// <returns>true if the value is null, otherwise false.</returns>
335         public bool IsCatalogNull()
336         {
337             return this.IsNull(this._tableTableDetails.CatalogColumn);
338         }
339
340         /// <summary>
341         /// Determines if the Schema column value is null
342         /// </summary>
343         /// <returns>true if the value is null, otherwise false.</returns>
344         public bool IsSchemaNull()
345         {
346             return this.IsNull(this._tableTableDetails.SchemaColumn);
347         }
348
349         /// <summary>
350         /// Determines if the DataType column value is null
351         /// </summary>
352         /// <returns>true if the value is null, otherwise false.</returns>
353         public bool IsDataTypeNull()
354         {
355             return this.IsNull(this._tableTableDetails.DataTypeColumn);
356         }
357
358         /// <summary>
359         /// Determines if the MaximumLength column value is null
360         /// </summary>
361         /// <returns>true if the value is null, otherwise false.</returns>
362         public bool IsMaximumLengthNull()
363         {
364             return this.IsNull(this._tableTableDetails.MaximumLengthColumn);
365         }
366
367         /// <summary>
368         /// Determines if the Precision column value is null
369         /// </summary>
370         /// <returns>true if the value is null, otherwise false.</returns>
371         public bool IsPrecisionNull()
372         {
373             return this.IsNull(this._tableTableDetails.PrecisionColumn);
374         }
375
376         /// <summary>
377         /// Determines if the DateTime Precision column value is null
378         /// </summary>
379         /// <returns>true if the value is null, otherwise false.</returns>
380         public bool IsDateTimePrecisionNull()
381         {
382             return this.IsNull(this._tableTableDetails.DateTimePrecisionColumn);
383         }
384
385
386         /// <summary>
387         /// Determines if the Scale column value is null
388         /// </summary>
389         /// <returns>true if the value is null, otherwise false.</returns>
390         public bool IsScaleNull()
391         {
392             return this.IsNull(this._tableTableDetails.ScaleColumn);
393         }
394
395         /// <summary>
396         /// Determines if the IsIdentity column value is null
397         /// </summary>
398         /// <returns>true if the value is null, otherwise false.</returns>
399         public bool IsIsIdentityNull()
400         {
401             return this.IsNull(this._tableTableDetails.IsIdentityColumn);
402         }
403
404         /// <summary>
405         /// Determines if the IsIdentity column value is null
406         /// </summary>
407         /// <returns>true if the value is null, otherwise false.</returns>
408         public bool IsIsServerGeneratedNull()
409         {
410             return this.IsNull(this._tableTableDetails.IsServerGeneratedColumn);
411         }
412
413         public string GetMostQualifiedTableName()
414         {
415             string name = string.Empty;
416             if (!IsCatalogNull())
417             {
418                 name = Catalog;
419             }
420
421             if (!IsSchemaNull())
422             {
423                 if (name != string.Empty)
424                 {
425                     name += ".";
426                 }
427                 name += Schema;
428             }
429
430             if (name != string.Empty)
431             {
432                 name += ".";
433             }
434
435             // TableName is not allowed to be null
436             name += TableName;
437
438             return name;
439         }
440
441         public EntityStoreSchemaGenerator.DbObjectKey CreateDbObjectKey(EntityStoreSchemaGenerator.DbObjectType objectType)
442         {
443             return new EntityStoreSchemaGenerator.DbObjectKey(
444                 this[this._tableTableDetails.CatalogColumn], 
445                 this[this._tableTableDetails.SchemaColumn],
446                 this[this._tableTableDetails.TableNameColumn],
447                 objectType);
448         }
449     }
450 }