📄 datamanager.cs
字号:
//------------------------------------------------------------------------------
// <autogenerated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </autogenerated>
//------------------------------------------------------------------------------
using System;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Reflection;
using OrmLib;
namespace ORMBiz
{
/// <summary>
/// Main entry point into the database.
/// 'Get' calls fetch data using the QueryCriteria object.
/// 'New' calls create new objects/rows.
/// The CommitAll() function will need to be called at the end.
/// </summary>
/// <example>
/// Example of retrieving a contact and some of it's child rows from the database.
/// <code>
/// DataManager dm = new DataManager(Config.Dsn);
/// dm.QueryCriteria.And(JoinPath.Contact.Teacher.Schedule.Columns.Duration,30,MatchType.GreaterOrEqual);
/// Contact c = dm.GetContact(FetchPath.Contact.Teacher.All);
/// </code>
/// Example of an insert
/// <code>
/// DataManager dm = new DataManager(Config.Dsn);
/// Contact c = dm.NewContact();
/// dm.CommitAll();
/// </code>
/// Example of fetching a collection of rows
/// <code>
/// DataManager dm = new DataManager(Config.Dsn);
/// ContactCollection c = dm.GetContactCollection(FetchPath.Contact.Teacher.All);
/// </code>
/// </example>
public class DataManager : DataManagerBase
{
/// <summary>
/// Constructor for dsn.
/// </summary>
public DataManager(string dsn) : base(dsn, OrmDataSet.NewDataSet()){}
/// <summary>
/// Constructor for connections.
/// </summary>
public DataManager(SqlConnection connection) : base(connection, OrmDataSet.NewDataSet()){}
/// <summary>
/// Constructor for transactions.
/// </summary>
public DataManager(SqlTransaction transaction) : base(transaction, OrmDataSet.NewDataSet()){}
/// <summary>
/// Lookup object for static tables
/// </summary>
/// <remarks>
/// This is an internal field and should not be used.
/// </remarks>
internal Lookups lookups;
/// <summary>
/// Fetches the lookup object
/// TODO: refresh the lookup object
/// </summary>
/// <remarks>
/// This is an internal method and should not be used.
/// </remarks>
/// <returns></returns>
internal Lookups GetLookups()
{
if (lookups == null)
{
lookups = new Lookups(this.Dsn);
}
return lookups;
}
/// <summary>
/// Creates a new Column.
/// </summary>
/// <remarks>
/// <see cref="OrmLib.DataManagerBase.CommitAll"/> to have this written to the database.
/// </remarks>
/// <returns>A new Column object</returns>
public ORMBiz.Column NewColumn()
{
DataRow dr = DataSet.Tables["Column"].NewRow();
DataSet.Tables["Column"].Rows.Add( dr );
ORMBiz.Column _Column = new ORMBiz.Column(this, dr);
return _Column;
}
/// <summary>
/// Gets a ORMBiz.Column based on the criteria specified by QueryCriteria.And(..).
/// </summary>
/// <param name="relations">Specify which related tables should be fetched during this query</param>
/// <returns>A Column, or null if not found</returns>
public ORMBiz.Column GetColumn(params DataManagerBase.FetchPathRelation[] relations)
{
DataSet ds = new DataSet();
FillDataSet( CreateSql("Column", relations), ds, false);
DataRow ColumnRow = GetRow(ds, "Column");
if ( ColumnRow == null ) return null;
return new ORMBiz.Column (this, ColumnRow);
}
/// <summary>
/// Gets a ORMBiz.Column from the already loaded records in this DataManager, by primary key.
/// </summary>
/// <remarks>
/// This method is made available for when the dataset has been serialized
/// from session state or disk.
/// </remarks>
/// <example>
/// This example shows a reason to use this method.
/// <code>
/// /* first web page - save dataset and primary keys */
/// Session["DataSet"] = dm.DataSet;
/// Session["ColumnID"] = _Column.ID;
///
/// /* second web page - need to get currend contact */
/// DataManager dm = new DataManager(Config.Dsn);
/// dm.DataSet = (DataSet)Session["DataSet"];
/// _Column = dm.GetContactFromDataSet((System.Int32)Session["ColumnID"]);
/// </code>
/// </example>
/// <param name="ID">Primary key of the data row to retrieve.</param>
/// <returns>A Column, or null if not found</returns>
public ORMBiz.Column GetColumnFromDataSet(System.Int32 ID)
{
DataRow ColumnRow = null;
foreach(DataRow dr in DataSet.Tables["Column"].Rows)
{
if ( ((System.Int32)dr["ID"]).ToString() == ID.ToString() )
{
ColumnRow = dr;
break;
}
}
if ( ColumnRow == null) return null;
return new ORMBiz.Column (this, ColumnRow);
}
/// <summary>
/// Gets multiple Columns based on the criteria specified by QueryCriteria.And(..).
/// </summary>
/// <returns>A collection of Column objects</returns>
public ORMBiz.ColumnCollection GetColumnCollection()
{
return GetColumnCollection(FetchPath.Column);
}
/// <summary>
/// Gets multiple Columns based on the criteria specified by AddCriteria(..).
/// </summary>
/// <param name="relations">Specify which related tables should be fetched during this query</param>
/// <returns>A collection of Column objects</returns>
public ORMBiz.ColumnCollection GetColumnCollection(params DataManagerBase.FetchPathRelation[] relations)
{
DataSet ds = new DataSet();
FillDataSet(CreateSql("Column", relations), ds, false);
DataRow[] ColumnList = GetRows(ds,"Column");
if ( ColumnList == null ) return null;
ORMBiz.ColumnCollection a = new ORMBiz.ColumnCollection();
foreach ( DataRow dr in ColumnList )
a.Add(new ORMBiz.Column( this, dr ));
// must be added afterwards
a.DataManager = this;
return a;
}
/// <summary>
/// Gets a collection of Column from the already loaded records in this DataManager instance.
/// </summary>
/// <remarks>
/// This method is made available for when the dataset has been serialized
/// from session state or disk. This method will return all Column loaded.
/// </remarks>
/// <example>
/// This example shows a reason to use this method.
/// <code>
/// /* first web page - save dataset and primary keys */
/// Session["DataSet"] = dm.DataSet;
/// Session["ColumnID"] = _Column.ID;
///
/// /* second web page - need to get current contact */
/// DataManager dm = new DataManager(Config.Dsn);
/// dm.DataSet = (DataSet)Session["DataSet"];
/// _Column = dm.GetContactFromDataSet((int)Session["ColumnID"]);
/// </code>
/// </example>
/// <returns>A collection of Column objects.</returns>
public ORMBiz.ColumnCollection GetColumnCollectionFromDataSet()
{
DataRow[] ColumnList = GetRows(DataSet, "Column");
ORMBiz.ColumnCollection a = new ORMBiz.ColumnCollection();
foreach(DataRow dr in ColumnList )
a.Add( new ORMBiz.Column(this, dr));
// must be added afterwards
a.DataManager = this;
return a;
}
/// <summary>
/// Creates a new Database.
/// </summary>
/// <remarks>
/// <see cref="OrmLib.DataManagerBase.CommitAll"/> to have this written to the database.
/// </remarks>
/// <returns>A new Database object</returns>
public ORMBiz.Database NewDatabase()
{
DataRow dr = DataSet.Tables["Database"].NewRow();
DataSet.Tables["Database"].Rows.Add( dr );
ORMBiz.Database _Database = new ORMBiz.Database(this, dr);
return _Database;
}
/// <summary>
/// Gets a ORMBiz.Database based on the criteria specified by QueryCriteria.And(..).
/// </summary>
/// <param name="relations">Specify which related tables should be fetched during this query</param>
/// <returns>A Database, or null if not found</returns>
public ORMBiz.Database GetDatabase(params DataManagerBase.FetchPathRelation[] relations)
{
DataSet ds = new DataSet();
FillDataSet( CreateSql("Database", relations), ds, false);
DataRow DatabaseRow = GetRow(ds, "Database");
if ( DatabaseRow == null ) return null;
return new ORMBiz.Database (this, DatabaseRow);
}
/// <summary>
/// Gets a ORMBiz.Database from the already loaded records in this DataManager, by primary key.
/// </summary>
/// <remarks>
/// This method is made available for when the dataset has been serialized
/// from session state or disk.
/// </remarks>
/// <example>
/// This example shows a reason to use this method.
/// <code>
/// /* first web page - save dataset and primary keys */
/// Session["DataSet"] = dm.DataSet;
/// Session["DatabaseID"] = _Database.ID;
///
/// /* second web page - need to get currend contact */
/// DataManager dm = new DataManager(Config.Dsn);
/// dm.DataSet = (DataSet)Session["DataSet"];
/// _Database = dm.GetContactFromDataSet((System.Int32)Session["DatabaseID"]);
/// </code>
/// </example>
/// <param name="ID">Primary key of the data row to retrieve.</param>
/// <returns>A Database, or null if not found</returns>
public ORMBiz.Database GetDatabaseFromDataSet(System.Int32 ID)
{
DataRow DatabaseRow = null;
foreach(DataRow dr in DataSet.Tables["Database"].Rows)
{
if ( ((System.Int32)dr["ID"]).ToString() == ID.ToString() )
{
DatabaseRow = dr;
break;
}
}
if ( DatabaseRow == null) return null;
return new ORMBiz.Database (this, DatabaseRow);
}
/// <summary>
/// Gets multiple Databases based on the criteria specified by QueryCriteria.And(..).
/// </summary>
/// <returns>A collection of Database objects</returns>
public ORMBiz.DatabaseCollection GetDatabaseCollection()
{
return GetDatabaseCollection(FetchPath.Database);
}
/// <summary>
/// Gets multiple Databases based on the criteria specified by AddCriteria(..).
/// </summary>
/// <param name="relations">Specify which related tables should be fetched during this query</param>
/// <returns>A collection of Database objects</returns>
public ORMBiz.DatabaseCollection GetDatabaseCollection(params DataManagerBase.FetchPathRelation[] relations)
{
DataSet ds = new DataSet();
FillDataSet(CreateSql("Database", relations), ds, false);
DataRow[] DatabaseList = GetRows(ds,"Database");
if ( DatabaseList == null ) return null;
ORMBiz.DatabaseCollection a = new ORMBiz.DatabaseCollection();
foreach ( DataRow dr in DatabaseList )
a.Add(new ORMBiz.Database( this, dr ));
// must be added afterwards
a.DataManager = this;
return a;
}
/// <summary>
/// Gets a collection of Database from the already loaded records in this DataManager instance.
/// </summary>
/// <remarks>
/// This method is made available for when the dataset has been serialized
/// from session state or disk. This method will return all Database loaded.
/// </remarks>
/// <example>
/// This example shows a reason to use this method.
/// <code>
/// /* first web page - save dataset and primary keys */
/// Session["DataSet"] = dm.DataSet;
/// Session["DatabaseID"] = _Database.ID;
///
/// /* second web page - need to get current contact */
/// DataManager dm = new DataManager(Config.Dsn);
/// dm.DataSet = (DataSet)Session["DataSet"];
/// _Database = dm.GetContactFromDataSet((int)Session["DatabaseID"]);
/// </code>
/// </example>
/// <returns>A collection of Database objects.</returns>
public ORMBiz.DatabaseCollection GetDatabaseCollectionFromDataSet()
{
DataRow[] DatabaseList = GetRows(DataSet, "Database");
ORMBiz.DatabaseCollection a = new ORMBiz.DatabaseCollection();
foreach(DataRow dr in DatabaseList )
a.Add( new ORMBiz.Database(this, dr));
// must be added afterwards
a.DataManager = this;
return a;
}
/// <summary>
/// Creates a new DataType.
/// </summary>
/// <remarks>
/// <see cref="OrmLib.DataManagerBase.CommitAll"/> to have this written to the database.
/// </remarks>
/// <returns>A new DataType object</returns>
public ORMBiz.DataType NewDataType()
{
DataRow dr = DataSet.Tables["DataType"].NewRow();
DataSet.Tables["DataType"].Rows.Add( dr );
ORMBiz.DataType _DataType = new ORMBiz.DataType(this, dr);
return _DataType;
}
/// <summary>
/// Gets a ORMBiz.DataType based on the criteria specified by QueryCriteria.And(..).
/// </summary>
/// <param name="relations">Specify which related tables should be fetched during this query</param>
/// <returns>A DataType, or null if not found</returns>
public ORMBiz.DataType GetDataType(params DataManagerBase.FetchPathRelation[] relations)
{
DataSet ds = new DataSet();
FillDataSet( CreateSql("DataType", relations), ds, false);
DataRow DataTypeRow = GetRow(ds, "DataType");
if ( DataTypeRow == null ) return null;
return new ORMBiz.DataType (this, DataTypeRow);
}
/// <summary>
/// Gets a ORMBiz.DataType from the already loaded records in this DataManager, by primary key.
/// </summary>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -