+2006-11-28 Nagappan A <anagappan@novell.com>
+
+ * DataRelation.cs (DataRelation): Added 2.0 profile constructor to
+ take parentTableNameSpace and childTableNameSpace as argument.
+ (FinishInit): Update parentTableNameSpace and childTableNameSpace,
+ when the string is not empty in 2.0 profile.
+
+ * DataRowCollection.cs: Implemented Count public property.
+ Added !NET_2_0 for List protected property, as it has been removed
+ in 2.0 prifle.
+ (IndexOf): Implemented new public method.
+ (CopyTo): Implemented new public override method.
+ (GetEnumerator): Implemented new public override method.
+
+ * DataTable.cs (Load): Throw ArgumentNullException, when reader
+ argument is null.
+ (WriteXmlSchema): Throw InvalidOperationException, when table name
+ is empty. When DataSet Namespace is set, append that with '_x003A_'
+ and table name.
+
+ * DataSet.cs (Load): Throw ArgumentNullException, when reader
+ argument is null.
+
+ * XmlSchemaWriter.cs (WriteSchema): Modified UseCurrentCulture to
+ UseCurrentLocale.
+ (WriteDataSetElement): Added minOccurs attribute.
+ (WriteConstraints): Check for tables length, if > 1 then add the
+ relations to XmlSchema.
+
2006-11-21 Nagappan A <anagappan@novell.com>
* DataView.cs: Added public event Initialized.
\r
#region Methods\r
\r
-/* ??\r
- [MonoTODO]\r
- protected internal void CheckNotAllowNull() {\r
- }\r
-\r
- [MonoTODO]\r
- protected void CheckUnique() {\r
- }\r
-*/\r
[MonoTODO]\r
internal DataColumn Clone() {\r
DataColumn copy = new DataColumn ();\r
string[] _childColumnNames;
bool _nested;
bool initInProgress = false;
+#if NET_2_0
+ string _parentTableNameSpace = String.Empty;
+ string _childTableNameSpace = String.Empty;
+#endif
#region Constructors
"matching column types");
}
- [MonoTODO]
[Browsable (false)]
public DataRelation (string relationName, string parentTableName, string childTableName, string[] parentColumnNames, string[] childColumnNames, bool nested)
{
_nested = nested;
InitInProgress = true;
}
+
+#if NET_2_0
+ [Browsable (false)]
+ public DataRelation (string relationName, string parentTableName,
+ string parentTableNameSpace, string childTableName,
+ string childTableNameSpace, string[] parentColumnNames,
+ string[] childColumnNames, bool nested)
+ {
+ _relationName = relationName;
+ _parentTableName = parentTableName;
+ _parentTableNameSpace = parentTableNameSpace;
+ _childTableName = childTableName;
+ _childTableNameSpace = childTableNameSpace;
+ _parentColumnNames = parentColumnNames;
+ _childColumnNames = childColumnNames;
+ _nested = nested;
+ InitInProgress = true;
+ }
+#endif
internal bool InitInProgress {
get { return initInProgress; }
this.createConstraints = false;
this.extendedProperties = new PropertyCollection ();
InitInProgress = false;
- }
#if NET_2_0
- [MonoTODO]
- public DataRelation (string relationName, string parentTableName, string parentTableNamespace, string childTableName, string childTableNamespace, string[] parentColumnNames, string[] childColumnNames, bool nested)
- {
- throw new NotImplementedException ();
- }
+ if (_parentTableNameSpace != String.Empty) {
+ parent.Namespace = _parentTableNameSpace;
+ }
+ if (_childTableNameSpace != String.Empty) {
+ child.Namespace = _childTableNameSpace;
+ }
#endif
+ }
#endregion // Constructors
/// Adds a DataRelation to the DataRelationCollection.
/// </summary>
/// <param name="relation">The DataRelation to add to the collection.</param>
- [MonoTODO]
public void Add(DataRelation relation)
{
// To prevent endless recursion
try
{
+ CollectionChangeEventArgs e = new CollectionChangeEventArgs (CollectionChangeAction.Add, this);
+ OnCollectionChanging (e);
+
this.AddCore (relation);
if(relation.RelationName == string.Empty)
relation.RelationName = GenerateRelationName();
relation.ParentTable.ResetPropertyDescriptorsCache();
relation.ChildTable.ResetPropertyDescriptorsCache();
- CollectionChangeEventArgs e = new CollectionChangeEventArgs(CollectionChangeAction.Add, this);
- OnCollectionChanged(e);
+ e = new CollectionChangeEventArgs (CollectionChangeAction.Add, this);
+ OnCollectionChanged (e);
}
finally
{
/// Adds to the list
/// </summary>
/// <param name="relation">The relation to check.</param>
- [MonoTODO]
protected virtual void AddCore(DataRelation relation)
{
if (relation == null) {
}
[MonoTODO]
- protected internal virtual void OnCollectionChanging (CollectionChangeEventArgs ccevent)
+ protected virtual void OnCollectionChanging (CollectionChangeEventArgs ccevent)
{
- throw new NotImplementedException ();
+ //throw new NotImplementedException ();
}
public void Remove (DataRelation relation)
if (!(List.Contains(relation)))
throw new ArgumentException("Relation doesnot belong to this Collection.");
+ OnCollectionChanging (CreateCollectionChangeEvent (CollectionChangeAction.Remove));
+
RemoveCore (relation);
string name = "Relation" + index;
if (relation.RelationName == name)
Remove(relation);
}
- [MonoTODO]
protected virtual void RemoveCore(DataRelation relation)
{
// Remove from collection
}
}
+ public override int Count
+ {
+ get {
+ return List.Count;
+ }
+ }
+
+#if !NET_2_0
/// <summary>
/// This member overrides InternalDataCollectionBase.List
/// </summary>
protected override ArrayList List
{
get { return base.List; }
- }
+ }
+#endif
/// <summary>
/// Adds the specified DataRow to the DataRowCollection object.
AddInternal(row);
}
+#if NET_2_0
+ public int IndexOf (DataRow row)
+ {
+ if (row == null)
+ return -1;
+
+ int i = 0;
+ foreach (DataRow dr in this) {
+ if (dr == row) {
+ return i;
+ }
+ i++;
+ }
+
+ return -1;
+ }
+#endif
internal void AddInternal (DataRow row) {
AddInternal (row, DataRowAction.Add);
}
return Find (keys) != null;
}
+#if NET_2_0
public void CopyTo (DataRow [] array, int index)
{
CopyTo ((Array) array, index);
}
+ public override void CopyTo (Array array, int index)
+ {
+ base.CopyTo (array, index);
+ }
+
+ public override IEnumerator GetEnumerator ()
+ {
+ return base.GetEnumerator ();
+ }
+#endif
+
/// <summary>
/// Gets the row specified by the primary key value.
/// </summary>
#if NET_2_0\r
public void Load (IDataReader reader, LoadOption loadOption, params DataTable[] tables)\r
{\r
- if (reader == null)\r
- return;\r
+ if (reader == null) {\r
+ throw new ArgumentNullException ("Value cannot be null. Parameter name: reader");\r
+ }\r
foreach (DataTable dt in tables) {\r
if (dt.DataSet == null || dt.DataSet != this) {\r
throw new ArgumentException ("Table " + dt.TableName + " does not belong to this DataSet.");\r
\r
public void Load (IDataReader reader, LoadOption loadOption, params string[] tables)\r
{\r
- if (reader == null)\r
- return;\r
+ if (reader == null) {\r
+ throw new ArgumentNullException ("Value cannot be null. Parameter name: reader");\r
+ }\r
foreach (string tableName in tables) {\r
DataTable dt = Tables [tableName];\r
\r
\r
public void Load (IDataReader reader, LoadOption loadOption, FillErrorEventHandler errorHandler, params DataTable[] tables)\r
{\r
- if (reader == null)\r
- return;\r
+ if (reader == null) {\r
+ throw new ArgumentNullException ("Value cannot be null. Parameter name: reader");\r
+ }\r
foreach (DataTable dt in tables) {\r
if (dt.DataSet == null || dt.DataSet != this) {\r
throw new ArgumentException ("Table " + dt.TableName + " does not belong to this DataSet.");\r
/// </summary>\r
public void Load (IDataReader reader)\r
{\r
- if (reader == null)\r
- return;\r
+ if (reader == null) {\r
+ throw new ArgumentNullException ("Value cannot be null. Parameter name: reader");\r
+ }\r
Load (reader, LoadOption.PreserveChanges);\r
}\r
\r
/// </summary>\r
public void Load (IDataReader reader, LoadOption loadOption)\r
{\r
- if (reader == null)\r
- return;\r
+ if (reader == null) {\r
+ throw new ArgumentNullException ("Value cannot be null. Parameter name: reader");\r
+ }\r
bool prevEnforceConstr = this.EnforceConstraints;\r
try {\r
this.EnforceConstraints = false;\r
\r
public virtual void Load (IDataReader reader, LoadOption loadOption, FillErrorEventHandler errorHandler)\r
{\r
- if (reader == null)\r
- return;\r
+ if (reader == null) {\r
+ throw new ArgumentNullException ("Value cannot be null. Parameter name: reader");\r
+ }\r
bool prevEnforceConstr = this.EnforceConstraints;\r
try {\r
this.EnforceConstraints = false;\r
\r
public void WriteXmlSchema (Stream stream)\r
{\r
+ if (TableName == "") {\r
+ throw new InvalidOperationException ("Cannot serialize the DataTable. DataTable name is not set.");\r
+ }\r
XmlWriterSettings s = GetWriterSettings ();\r
s.OmitXmlDeclaration = false;\r
WriteXmlSchema (XmlWriter.Create (stream, s));\r
\r
public void WriteXmlSchema (TextWriter writer)\r
{\r
+ if (TableName == "") {\r
+ throw new InvalidOperationException ("Cannot serialize the DataTable. DataTable name is not set.");\r
+ }\r
XmlWriterSettings s = GetWriterSettings ();\r
s.OmitXmlDeclaration = false;\r
WriteXmlSchema (XmlWriter.Create (writer, s));\r
\r
public void WriteXmlSchema (XmlWriter writer)\r
{\r
+ if (TableName == "") {\r
+ throw new InvalidOperationException ("Cannot serialize the DataTable. DataTable name is not set.");\r
+ }\r
DataSet ds = DataSet;\r
DataSet tmp = null;\r
try {\r
col.Add (this);\r
DataTable [] tables = new DataTable [col.Count];\r
for (int i = 0; i < col.Count; i++) tables[i] = col[i];\r
- XmlSchemaWriter.WriteXmlSchema (writer, tables, null, TableName, ds.DataSetName);\r
+ string tableName;\r
+ if (ds.Namespace == "")\r
+ tableName = TableName;\r
+ else\r
+ tableName = ds.Namespace + "_x003A_" + TableName;\r
+ XmlSchemaWriter.WriteXmlSchema (writer, tables, null, tableName, ds.DataSetName);\r
} finally {\r
if (tmp != null)\r
ds.Tables.Remove (this);\r
\r
public void WriteXmlSchema (string fileName)\r
{\r
+ if (fileName == "") {\r
+ throw new ArgumentException ("Empty path name is not legal.");\r
+ }\r
+ if (TableName == "") {\r
+ throw new InvalidOperationException ("Cannot serialize the DataTable. DataTable name is not set.");\r
+ }\r
XmlWriter xw = null;\r
try {\r
XmlWriterSettings s = GetWriterSettings ();\r
xw = XmlWriter.Create (fileName, s);\r
WriteXmlSchema (xw);\r
} finally {\r
- if (xw != null)\r
+ if (xw != null) {\r
xw.Close ();\r
+ }\r
}\r
}\r
\r
public void WriteXmlSchema (Stream stream, bool writeHierarchy)\r
{\r
+ if (TableName == "") {\r
+ throw new InvalidOperationException ("Cannot serialize the DataTable. DataTable name is not set.");\r
+ }\r
XmlWriterSettings s = GetWriterSettings ();\r
s.OmitXmlDeclaration = false;\r
WriteXmlSchema (XmlWriter.Create (stream, s), writeHierarchy);\r
\r
public void WriteXmlSchema (TextWriter writer, bool writeHierarchy)\r
{\r
+ if (TableName == "") {\r
+ throw new InvalidOperationException ("Cannot serialize the DataTable. DataTable name is not set.");\r
+ }\r
XmlWriterSettings s = GetWriterSettings ();\r
s.OmitXmlDeclaration = false;\r
WriteXmlSchema (XmlWriter.Create (writer, s), writeHierarchy);\r
\r
public void WriteXmlSchema (XmlWriter writer, bool writeHierarchy)\r
{\r
+ if (TableName == "") {\r
+ throw new InvalidOperationException ("Cannot serialize the DataTable. DataTable name is not set.");\r
+ }\r
if (writeHierarchy == false) {\r
WriteXmlSchema (writer);\r
}\r
}\r
writer.WriteStartDocument ();\r
//XmlSchemaWriter.WriteXmlSchema (ds, writer);\r
- DataTable [] tables = new DataTable [ds.Tables.Count];\r
- DataRelation [] relations = new DataRelation [ds.Relations.Count];\r
- for (int i = 0; i < ds.Tables.Count; i++) tables[i] = ds.Tables[i];\r
- for (int i = 0; i < ds.Relations.Count; i++) relations[i] = ds.Relations[i];\r
- XmlSchemaWriter.WriteXmlSchema (writer, tables, relations, TableName, ds.DataSetName);\r
+ //DataTable [] tables = new DataTable [ds.Tables.Count];\r
+ DataTable [] tables = null;\r
+ //DataRelation [] relations = new DataRelation [ds.Relations.Count];\r
+ //for (int i = 0; i < ds.Relations.Count; i++) {\r
+ // relations[i] = ds.Relations[i];\r
+ //}\r
+ DataRelation [] relations = null;\r
+ if (ChildRelations.Count > 0) {\r
+ relations = new DataRelation [ChildRelations.Count];\r
+ for (int i = 0; i < ChildRelations.Count; i++) {\r
+ relations [i] = ChildRelations [i];\r
+ }\r
+ tables = new DataTable [ds.Tables.Count];\r
+ for (int i = 0; i < ds.Tables.Count; i++) tables [i] = ds.Tables [i];\r
+ } else {\r
+ tables = new DataTable [1];\r
+ tables [0] = this;\r
+ }\r
+\r
+ string tableName;\r
+ if (ds.Namespace == "")\r
+ tableName = TableName;\r
+ else\r
+ tableName = ds.Namespace + "_x003A_" + TableName;\r
+ XmlSchemaWriter.WriteXmlSchema (writer, tables, relations, tableName, ds.DataSetName);\r
} finally {\r
if (tmp != null)\r
ds.Tables.Remove (this);\r
\r
public void WriteXmlSchema (string fileName, bool writeHierarchy)\r
{\r
+ if (fileName == "") {\r
+ throw new ArgumentException ("Empty path name is not legal.");\r
+ }\r
+ if (TableName == "") {\r
+ throw new InvalidOperationException ("Cannot serialize the DataTable. DataTable name is not set.");\r
+ }\r
XmlWriter xw = null;\r
try {\r
XmlWriterSettings s = GetWriterSettings ();\r
if (dataSetLocale == CultureInfo.CurrentCulture) {
w.WriteAttributeString (
XmlConstants.MsdataPrefix,
- "UseCurrentCulture",
+ "UseCurrentLocale",
XmlConstants.MsdataNamespace,
"true");
}
w.WriteStartElement ("xs", "complexType", xmlnsxs);
w.WriteStartElement ("xs", "choice", xmlnsxs);
+ w.WriteAttributeString ("minOccurs", "0");
w.WriteAttributeString ("maxOccurs", "unbounded");
foreach (DataTable table in tables) {
ForeignKeyConstraint fk = c as ForeignKeyConstraint;
bool haveConstraint = false;
- if (relations != null)
+ if (relations != null) {
foreach (DataRelation r in relations)
- if(r.RelationName == fk.ConstraintName)
+ if (r.RelationName == fk.ConstraintName)
haveConstraint = true;
- if (fk != null && !haveConstraint) {
+ }
+ if (tables.Length > 1 && fk != null && !haveConstraint) {
DataRelation rel = new DataRelation (fk.ConstraintName,
fk.RelatedColumns, fk.Columns);
AddForeignKeys (rel, names, true);