#region License
// Copyright 2005-2019 Paul Kohler (https://github.com/paulkohler/minisqlquery). All rights reserved.
// This source code is made available under the terms of the GNU Lesser General Public License v3.0
// https://github.com/paulkohler/minisqlquery/blob/master/LICENSE
#endregion
using System;
using System.Collections.Generic;
namespace MiniSqlQuery.Core.DbModel
{
/// The db model instance.
public class DbModelInstance
{
/// The _tables.
private readonly List _tables;
/// The _views.
private readonly List _views;
/// Initializes a new instance of the class.
public DbModelInstance()
{
_tables = new List();
_views = new List();
}
/// Gets or sets ConnectionString.
/// The connection string.
public string ConnectionString { get; set; }
/// Gets or sets ProviderName.
/// The provider name.
public string ProviderName { get; set; }
/// Gets Tables.
/// The tables.
public virtual ICollection Tables
{
get { return _tables; }
}
/// Gets or sets Types.
/// The types.
public Dictionary Types { get; set; }
/// Gets Views.
/// The views.
public virtual ICollection Views
{
get { return _views; }
}
/// The add.
/// The table.
public virtual void Add(DbModelTable table)
{
table.ParentDb = this;
_tables.Add(table);
}
/// The add.
/// The view.
public virtual void Add(DbModelView view)
{
view.ParentDb = this;
_views.Add(view);
}
/// The find table.
/// The table name.
///
public virtual DbModelTable FindTable(string tableName)
{
return _tables.Find(table => table.FullName.Equals(tableName, StringComparison.InvariantCultureIgnoreCase));
}
/// The find table or view.
/// The name.
///
public virtual DbModelTable FindTableOrView(string name)
{
var obj = _tables.Find(table => table.FullName.Equals(name, StringComparison.InvariantCultureIgnoreCase));
if (obj == null)
{
obj = _views.Find(view => view.FullName.Equals(name, StringComparison.InvariantCultureIgnoreCase));
}
return obj;
}
/// The find view.
/// The view name.
///
public virtual DbModelTable FindView(string viewName)
{
return _views.Find(view => view.FullName.Equals(viewName, StringComparison.InvariantCultureIgnoreCase));
}
}
}