2013-07-24 07:35:32 +02:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
2013-03-30 22:56:34 +01:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using Marr.Data.Mapping;
|
|
|
|
|
|
|
|
|
|
namespace Marr.Data.QGen
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// This class represents a View. A view can hold multiple tables (and their columns).
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class View : Table, IEnumerable<Table>
|
|
|
|
|
{
|
|
|
|
|
private string _viewName;
|
|
|
|
|
private Table[] _tables;
|
2013-07-24 07:35:32 +02:00
|
|
|
|
private ColumnMapCollection _columns;
|
2013-03-30 22:56:34 +01:00
|
|
|
|
|
|
|
|
|
public View(string viewName, Table[] tables)
|
|
|
|
|
: base(tables[0].EntityType, JoinType.None)
|
|
|
|
|
{
|
|
|
|
|
_viewName = viewName;
|
|
|
|
|
_tables = tables;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Table[] Tables
|
|
|
|
|
{
|
|
|
|
|
get { return _tables; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string Name
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _viewName;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_viewName = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string Alias
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return base.Alias;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
base.Alias = value;
|
|
|
|
|
|
|
|
|
|
// Sync view tables
|
|
|
|
|
foreach (Table table in _tables)
|
|
|
|
|
{
|
|
|
|
|
table.Alias = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets all the columns from all the tables included in the view.
|
|
|
|
|
/// </summary>
|
2013-07-24 07:35:32 +02:00
|
|
|
|
public override ColumnMapCollection Columns
|
2013-03-30 22:56:34 +01:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (_columns == null)
|
|
|
|
|
{
|
|
|
|
|
var allColumns = _tables.SelectMany(t => t.Columns);
|
|
|
|
|
_columns = new ColumnMapCollection();
|
|
|
|
|
_columns.AddRange(allColumns);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _columns;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerator<Table> GetEnumerator()
|
|
|
|
|
{
|
|
|
|
|
foreach (Table table in _tables)
|
|
|
|
|
{
|
|
|
|
|
yield return table;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-24 07:35:32 +02:00
|
|
|
|
IEnumerator IEnumerable.GetEnumerator()
|
2013-03-30 22:56:34 +01:00
|
|
|
|
{
|
2013-07-24 07:35:32 +02:00
|
|
|
|
return GetEnumerator();
|
2013-03-30 22:56:34 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|