本文整理汇总了C#中IDatabase.GetTable方法的典型用法代码示例。如果您正苦于以下问题:C# IDatabase.GetTable方法的具体用法?C# IDatabase.GetTable怎么用?C# IDatabase.GetTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDatabase
的用法示例。
在下文中一共展示了IDatabase.GetTable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GDadaDbHelper
public GDadaDbHelper()
{
ServicePointManager.ServerCertificateValidationCallback = RemoteCertificateValidationCallback;
_databaseClient = new DatabaseClient(Email,
File.ReadAllBytes(Application.dataPath + KeyPath));
_database = _databaseClient.GetDatabase("test_table") ?? _databaseClient.CreateDatabase("test_table");
_scoresTable = _database.GetTable<UserScore>("Scores") ?? _database.CreateTable<UserScore>("Scores");
}
示例2: FixtureSetup
public void FixtureSetup()
{
Console.WriteLine("Connecting");
var client = new DatabaseClient("[email protected]", "password");
const string dbName = "IntegrationTests";
Console.WriteLine("Opening or creating database");
db = client.GetDatabase(dbName) ?? client.CreateDatabase(dbName);
const string tableName = "IntegrationTests";
Console.WriteLine("Opening or creating table");
table = db.GetTable<IntegrationEntity>(tableName) ?? db.CreateTable<IntegrationEntity>(tableName);
}
示例3: FixtureSetup
public void FixtureSetup() {
Console.WriteLine("Connecting");
var client = new DatabaseClient(
clientEmail: "[email protected]",
privateKey: File.ReadAllBytes(@"xxx.p12"));
const string dbName = "IntegrationTests";
Console.WriteLine("Opening or creating database");
db = client.GetDatabase(dbName) ?? client.CreateDatabase(dbName);
const string tableName = "IntegrationTests";
Console.WriteLine("Opening or creating table");
table = db.GetTable<IntegrationEntity>(tableName) ?? db.CreateTable<IntegrationEntity>(tableName);
}
示例4: DeserialiseComponentMapping
public ComponentMapping DeserialiseComponentMapping(XmlNode mappingNode, IDatabase database, EntitySet set)
{
NodeProcessor proc = new NodeProcessor(mappingNode);
ComponentMapping mapping = new ComponentMappingImpl();
mapping.FromTable = database.GetTable(proc.GetString("FromTable"), proc.GetString("FromSchema"));
NodeProcessor specProcessor = new NodeProcessor(mappingNode.SelectSingleNode("ToComponent"));
var specification = set.GetComponentSpecification(specProcessor.Attributes.GetString("specification"));
var parentEntity = set.GetEntity(specProcessor.Attributes.GetString("parent-entity"));
string name = specProcessor.Attributes.GetString("name");
if (parentEntity == null)
throw new DeserialisationException(string.Format("Could not find the Entity named {0}", name));
if (specification == null)
throw new DeserialisationException(string.Format("Could not find the Component Specification named {0}", name));
var component = specification.ImplementedComponents.FirstOrDefault(c => ReferenceEquals(c.ParentEntity, parentEntity) && c.Name == name);
if (component == null)
throw new DeserialisationException(string.Format("Could not find the component named {0}", name));
mapping.ToComponent = component;
var columnNodes = mappingNode.SelectNodes("FromColumns/Column");
var propNodes = mappingNode.SelectNodes("ToProperties/Property");
if (columnNodes == null) throw new DeserialisationException("There were no columns in this Mapping xml");
if (propNodes == null) throw new DeserialisationException("There were no properties in this Mapping xml");
List<IColumn> columns = new List<IColumn>();
foreach (XmlNode columnNode in columnNodes)
{
columns.Add(mapping.FromTable.GetColumn(columnNode.InnerText));
}
List<ComponentPropertyMarker> properties = new List<ComponentPropertyMarker>();
foreach (XmlNode propNode in propNodes)
{
properties.Add(mapping.ToComponent.GetProperty(propNode.InnerText));
}
if (columns.Count != properties.Count) throw new DeserialisationException("Mapping contains different numbers of columns and properties");
for (int i = 0; i < columns.Count; i++)
{
mapping.AddPropertyAndColumn(properties[i], columns[i]);
}
ProcessScriptBase(mapping, mappingNode);
return mapping;
}
示例5: DeserialiseMapping
public Mapping DeserialiseMapping(XmlNode node, IDatabase database, EntitySet set)
{
NodeProcessor proc = new NodeProcessor(node);
Mapping mapping = new MappingImpl();
mapping.FromTable = database.GetTable(proc.GetString("FromTable"), proc.GetString("FromSchema"));
if (mapping.FromTable == null)
mapping.FromTable = database.GetView(proc.GetString("FromTable"), proc.GetString("FromSchema"));
mapping.ToEntity = set.GetEntity(proc.GetString("ToEntity"));
if (mapping.FromTable == null || mapping.ToEntity == null)
return null;
var columnNodes = node.SelectNodes("FromColumns/Column");
var propNodes = node.SelectNodes("ToProperties/Property");
if (columnNodes == null) throw new DeserialisationException("There were no columns in this Mapping xml");
if (propNodes == null) throw new DeserialisationException("There were no properties in this Mapping xml");
List<IColumn> columns = new List<IColumn>();
foreach (XmlNode columnNode in columnNodes)
columns.Add(mapping.FromTable.GetColumn(columnNode.InnerText));
List<Property> properties = new List<Property>();
foreach (XmlNode propNode in propNodes)
properties.Add(mapping.ToEntity.GetProperty(propNode.InnerText));
if (columns.Count != properties.Count) throw new DeserialisationException("Mapping contains different numbers of columns and properties");
for (int i = 0; i < columns.Count; i++)
{
if (properties[i] != null && columns[i] != null)
mapping.AddPropertyAndColumn(properties[i], columns[i]);
}
ProcessScriptBase(mapping, node);
return mapping;
}
示例6: ProcessUnionSubclasses
private void ProcessUnionSubclasses(object parent, MappingSet mappingSet, IDatabase database, EntitySet entities, Entity newEntity, IEnumerable<unionsubclass> unionsubclasses, ParseResults results, string unqualifiedNamespace)
{
if (unionsubclasses == null) return;
@class hClass = null;
unionsubclass parentSubClass = null;
if (parent is @class)
hClass = (@class)parent;
else
parentSubClass = (unionsubclass)parent;
foreach (unionsubclass hSubclass in unionsubclasses)
{
Entity childEntity;
string @namespace;
string name;
if (IsNameFullyQualified(hSubclass.name, out @namespace, out name))
{
childEntity = new EntityImpl(name);
string currentNamespace = ArchAngel.Interfaces.SharedData.CurrentProject.GetUserOption("ProjectNamespace") == null ? "" : ArchAngel.Interfaces.SharedData.CurrentProject.GetUserOption("ProjectNamespace").ToString();
if (string.IsNullOrWhiteSpace(currentNamespace))
ArchAngel.Interfaces.SharedData.CurrentProject.SetUserOption("ProjectNamespace", @namespace);
}
else
childEntity = new EntityImpl(hSubclass.name);
childEntity.SetEntityLazy(hSubclass.lazy);
newEntity.AddChild(childEntity);
var childTableMapping = new MappingImpl();
childTableMapping.FromTable = database.GetTable(hSubclass.table.UnBackTick(), hSubclass.schema.UnBackTick());
childTableMapping.ToEntity = childEntity;
foreach (var ip in childEntity.InheritedProperties)
{
PropertyImpl np = new PropertyImpl(ip);
np.IsHiddenByAbstractParent = true;
childEntity.AddProperty(np);
string columnName = "";
var props = hClass.Properties().ToList();
if (hClass != null)
{
property matchingProp = hClass.Properties().SingleOrDefault(p => p.name == ip.Name);
if (matchingProp != null)
{
if (matchingProp.column != null)
columnName = matchingProp.column;
else if (matchingProp.Columns().Count > 0)
columnName = matchingProp.Columns()[0].name;
}
else
{
if (hClass.Id().column1 != null)
columnName = hClass.Id().column1;
else if (hClass.Id().column != null && hClass.Id().column.Count() > 0)
columnName = hClass.Id().column[0].name;
}
}
else
columnName = parentSubClass.Properties().Single(p => p.name == ip.Name).column;
IColumn column = childTableMapping.FromTable.GetColumn(columnName.UnBackTick());
if (column != null)
childTableMapping.AddPropertyAndColumn(np, column);
}
foreach (var hProperty in hSubclass.Properties())
{
var property = CreateProperty(childEntity, childTableMapping, hProperty);
SetPropertyInfoFromParsedCode(property, results, unqualifiedNamespace, childTableMapping.FromTable.Schema, hSubclass.name);
}
// Add the parent's key properties as hidden properties
foreach (var keyProp in newEntity.Key.Properties)
{
Property childP = childEntity.PropertiesHiddenByAbstractParent.SingleOrDefault(p => p.Name == keyProp.Name);
if (childP != null)
{
//childP.IsHiddenByAbstractParent = true;
childP.IsKeyProperty = true;
}
}
entities.AddEntity(childEntity);
mappingSet.AddMapping(childTableMapping);
ProcessUnionSubclasses(hSubclass, mappingSet, database, entities, childEntity, hSubclass.unionsubclass1, results, unqualifiedNamespace);
}
}
示例7: ProcessSubclasses
private void ProcessSubclasses(MappingSet mappingSet, IDatabase database, EntitySet entities, Entity parentEntity, IEnumerable<subclass> subclasses, string schemaName, string tableName, ParseResults parseResults, string unqualifiedNamespace)
{
if (subclasses == null) return;
foreach (subclass hSubclass in subclasses)
{
Entity childEntity;
string @namespace;
string name;
if (IsNameFullyQualified(hSubclass.name, out @namespace, out name))
{
childEntity = new EntityImpl(name);
string currentNamespace = ArchAngel.Interfaces.SharedData.CurrentProject.GetUserOption("ProjectNamespace") == null ? "" : ArchAngel.Interfaces.SharedData.CurrentProject.GetUserOption("ProjectNamespace").ToString();
if (string.IsNullOrWhiteSpace(currentNamespace))
ArchAngel.Interfaces.SharedData.CurrentProject.SetUserOption("ProjectNamespace", @namespace);
}
else
childEntity = new EntityImpl(hSubclass.name);
childEntity.SetEntityLazy(hSubclass.lazy);
#region Discriminator
if (!string.IsNullOrWhiteSpace(hSubclass.discriminatorvalue))
{
childEntity.DiscriminatorValue = hSubclass.discriminatorvalue;
//ArchAngel.Providers.EntityModel.Model.EntityLayer.Discriminator d = new Discriminator()
//{
// AllowNull = xx,
// ColumnName = hSubclass.d,
// DiscriminatorType = xx,
// Force = xx,
// Formula = xx,
// Insert = xx
//};
//throw new NotImplementedException("TODO: fixup discriminator stuff");
//Grouping g = new AndGrouping();
//IColumn column = parentEntity.Discriminator.RootGrouping.Conditions[0].Column;
//ArchAngel.Providers.EntityModel.Model.DatabaseLayer.Discrimination.Operator op = ArchAngel.Providers.EntityModel.Model.DatabaseLayer.Discrimination.Operator.Equal;
//ExpressionValue value = new ExpressionValueImpl(hSubclass.discriminatorvalue);
//if (column != null && op != null && value != null)
// g.AddCondition(new ConditionImpl(column, op, value));
//if (childEntity.Discriminator == null)
// childEntity.Discriminator = new DiscriminatorImpl();
//childEntity.Discriminator.RootGrouping = g;
}
#endregion
parentEntity.AddChild(childEntity);
var childTableMapping = new MappingImpl();
childTableMapping.FromTable = database.GetTable(tableName, schemaName);
childTableMapping.ToEntity = childEntity;
foreach (var hProperty in hSubclass.Properties())
{
var property = CreateProperty(childEntity, childTableMapping, hProperty);
SetPropertyInfoFromParsedCode(property, parseResults, unqualifiedNamespace, childTableMapping.FromTable.Schema, hSubclass.name);
}
entities.AddEntity(childEntity);
mappingSet.AddMapping(childTableMapping);
ProcessSubclasses(mappingSet, database, entities, childEntity, hSubclass.subclass1, schemaName, tableName, parseResults, unqualifiedNamespace);
}
}
示例8: ProcessJoinedSubclasses
private void ProcessJoinedSubclasses(MappingSet mappingSet, IDatabase database, EntitySet entities, Entity newEntity, IEnumerable<joinedsubclass> joinedsubclasses, ParseResults results, string unqualifiedNamespace)
{
if (joinedsubclasses == null) return;
ITable parentTable = null;
if (newEntity.MappedTables().Count() > 0)
parentTable = newEntity.MappedTables().ElementAt(0);
foreach (joinedsubclass hSubclass in joinedsubclasses)
{
Entity childEntity;
string @namespace;
string name;
if (IsNameFullyQualified(hSubclass.name, out @namespace, out name))
{
childEntity = new EntityImpl(name);
string currentNamespace = ArchAngel.Interfaces.SharedData.CurrentProject.GetUserOption("ProjectNamespace") == null ? "" : ArchAngel.Interfaces.SharedData.CurrentProject.GetUserOption("ProjectNamespace").ToString();
if (string.IsNullOrWhiteSpace(currentNamespace))
ArchAngel.Interfaces.SharedData.CurrentProject.SetUserOption("ProjectNamespace", @namespace);
unqualifiedNamespace = @namespace;
}
else
childEntity = new EntityImpl(hSubclass.name);
childEntity.SetEntityLazy(hSubclass.lazy);
newEntity.AddChild(childEntity);
var childTableMapping = new MappingImpl();
ITable subClassTable;
if (!string.IsNullOrEmpty(hSubclass.table))
{
string schema = "";
if (!string.IsNullOrEmpty(hSubclass.schema))
schema = hSubclass.schema;
else if (parentTable != null)
schema = parentTable.Schema;
subClassTable = database.GetTable(hSubclass.table.UnBackTick(), schema.UnBackTick());
subClassTable.Database = database;
}
else
subClassTable = parentTable;
childTableMapping.FromTable = subClassTable;
childTableMapping.ToEntity = childEntity;
foreach (var hProperty in hSubclass.Properties())
{
var property = CreateProperty(childEntity, childTableMapping, hProperty);
SetPropertyInfoFromParsedCode(property, results, unqualifiedNamespace, childTableMapping.FromTable.Schema, hSubclass.name);
}
if (hSubclass.key != null)
{
string keyColumnName;
if (!string.IsNullOrEmpty(hSubclass.key.column1))
keyColumnName = hSubclass.key.column1;
else //if (hSubclass.key.column != null && hSubclass.key.column.Count() > 0)
keyColumnName = hSubclass.key.column[0].name;
Property keyProp = childEntity.Properties.FirstOrDefault(p => p.MappedColumn() != null && p.MappedColumn().Name == keyColumnName);
if (keyProp == null)
{
keyProp = CreateProperty(childEntity, childTableMapping, hSubclass.key, subClassTable);
SetPropertyInfoFromParsedCode(keyProp, results, unqualifiedNamespace, childTableMapping.FromTable.Schema, childEntity.Name);
keyProp.IsHiddenByAbstractParent = true;
}
keyProp.IsKeyProperty = true;
}
entities.AddEntity(childEntity);
mappingSet.AddMapping(childTableMapping);
ProcessJoinedSubclasses(mappingSet, database, entities, childEntity, hSubclass.joinedsubclass1, results, unqualifiedNamespace);
}
}
示例9: ProcessKeysNode
private void ProcessKeysNode(IDatabase database, XmlNode keysNode)
{
// ReSharper disable PossibleNullReferenceException
if (keysNode == null)
return;
string parentName = keysNode.SelectSingleNode("../Name").InnerText;
string parentSchema = keysNode.SelectSingleNode("../Schema").InnerText;
ITable parent = database.GetTable(parentName, parentSchema);
if (parent == null)
parent = database.GetView(parentName, parentSchema);
if (parent == null)
throw new Exception(string.Format("Table/View not found: {0}.{1}", parentSchema, parentName));
foreach (XmlNode keyNode in keysNode.SelectNodes("Key"))
{
IKey key = ProcessKeyNode(keyNode, parent, database);
parent.AddKey(key);
}
// ReSharper restore PossibleNullReferenceException
}
示例10: DeserialiseReferenceMapping
public TableReferenceMapping DeserialiseReferenceMapping(XmlNode referenceMappingNode, IDatabase database, EntitySet set)
{
NodeProcessor proc = new NodeProcessor(referenceMappingNode);
TableReferenceMapping mapping = new TableReferenceMappingImpl();
string fromTableName = proc.GetString("FromTable");
string fromSchema = proc.GetString("FromSchema");
Guid toReferenceIdentifier = proc.GetGuid("ToReference");
var reference = set.References.FirstOrDefault(r => r.Identifier == toReferenceIdentifier);
mapping.FromTable = database.GetTable(fromTableName, fromSchema);
mapping.ToReference = reference;
ProcessScriptBase(mapping, referenceMappingNode);
return mapping;
}
示例11: DeserialiseKeys
private void DeserialiseKeys(IDatabase database, XmlNodeList nodes)
{
// 1) Deserialise Primary Keys.
foreach (XmlNode tableNode in nodes)
{
var keyElements = tableNode.SelectSingleNode("Keys");
ProcessKeysNode(database, keyElements);
}
// 2) Deserialise Foreign Keys.
foreach (XmlNode tableNode in nodes)
{
ITable parent = database.GetTable(tableNode.SelectSingleNode("Name").InnerText, tableNode.SelectSingleNode("Schema").InnerText);
var keyElements = tableNode.SelectNodes("Keys/Key");
if (keyElements == null) continue;
foreach (XmlNode keyElement in keyElements)
{
IKey key = parent.GetKey(keyElement.SelectSingleNode("Name").InnerText);
ProcessReferencedKey(key, keyElement, database);
}
}
}
示例12: DeserialiseColumns
private void DeserialiseColumns(IDatabase database, XmlNodeList nodes)
{
foreach (XmlNode tableNode in nodes)
{
var columnsElement = tableNode.SelectSingleNode("Columns");
ITable table = database.GetTable(tableNode.SelectSingleNode("Name").InnerText, tableNode.SelectSingleNode("Schema").InnerText);
ProcessColumnsNode(table, columnsElement);
}
}
示例13: DeserialiseRelationship
public Relationship DeserialiseRelationship(XmlNode node, IDatabase database)
{
NodeProcessor proc = new NodeProcessor(node);
var rel = new RelationshipImpl();
rel.Identifier = proc.Attributes.GetGuid("identifier");
rel.Name = proc.GetString("Name");
ITable table1 = database.GetTable(proc.GetString("PrimaryTable"), proc.GetString("PrimarySchema"));
ITable table2 = database.GetTable(proc.GetString("ForeignTable"), proc.GetString("ForeignSchema"));
if (table1 == null)
table1 = database.GetView(proc.GetString("PrimaryTable"), proc.GetString("PrimarySchema"));
if (table2 == null)
table2 = database.GetView(proc.GetString("ForeignTable"), proc.GetString("ForeignSchema"));
if (table1 == null || table2 == null)
return null;
var key1 = table1.GetKey(proc.GetString("PrimaryKey"));
var key2 = table2.GetKey(proc.GetString("ForeignKey"));
if (key1 == null || key2 == null)
return null; // The foreign key has probably been removed
if (key1.Keytype == DatabaseKeyType.Foreign)
{
// The keys are around the wrong way.
var tempKey = key2;
key2 = key1;
key1 = tempKey;
var tempTable = table2;
table2 = table1;
table1 = tempTable;
}
rel.AddThisTo(table1, table2);
rel.PrimaryKey = key1;
rel.ForeignKey = key2;
rel.PrimaryCardinality = rel.ForeignKey.IsUnique ? Cardinality.One : Cardinality.Many;
rel.ForeignCardinality = rel.PrimaryKey.IsUnique ? Cardinality.One : Cardinality.Many;
rel.Database = database;
return rel;
}
示例14: GetForeignKeys
private void GetForeignKeys(IDatabase db)
{
DataTable keysTable = connector.GetForeignKeyConstraints();
foreach (DataRow keyRow in keysTable.Rows)
{
ITable parentTable = db.GetTable((string)keyRow["PrimaryTable"], "");
ITable foreignTable = db.GetTable((string)keyRow["ForeignTable"], "");
// Don't process keys of tables that the user hasn't selected
if (parentTable == null || foreignTable == null)
continue;
Key key = new Key
{
Name = keyRow["PrimaryKeyName"].ToString(),
IsUserDefined = false,
Keytype = DatabaseKeyType.Foreign,
Parent = parentTable
};
//////////////////
key.IsUnique = connector.GetUniqueIndexes().Select(string.Format("INDEX_NAME = '{0}'", key.Name)).Length > 0;
//foreignTable.AddKey(key);
//////////////////
// Get Foreign Key columns
DataRow[] foreignKeyColumns = connector.GetForeignKeyColumns().Select(string.Format("CONSTRAINT_NAME = '{0}' AND TABLE_NAME = '{1}'", key.Name.Replace("'", "''"), foreignTable.Name));
foreach (DataRow row in foreignKeyColumns)
key.AddColumn((string)row["COLUMN_NAME"]);
DataRow[] keyReferencedColumnRows =
connector.IndexReferencedColumns.Select(string.Format("ForeignKey = '{0}'", keyRow["CONSTRAINT_NAME"]));
DataRow firstKeyReferencedColumnRow = keyReferencedColumnRows[0];
// Fill References
key.ReferencedKey = foreignTable.GetKey((string)firstKeyReferencedColumnRow["ReferencedKey"]);
parentTable.AddKey(key);
}
return;
}
示例15: CreateMappingFor
private Mapping CreateMappingFor(Entity entity, @class hEntity, IDatabase database, string defaultSchema)
{
if (hEntity.table == null)
return null;
Mapping mapping = new MappingImpl();
string schema = string.IsNullOrEmpty(hEntity.schema) ? defaultSchema : hEntity.schema;
var table = database.GetTable(hEntity.table.UnBackTick(), schema.UnBackTick());
if (table == null)
{
// create the table
table = entityProcessor.CreateTable(entity);
database.AddTable(table);
}
mapping.FromTable = table;
mapping.ToEntity = entity;
return mapping;
}