本文整理汇总了C#中TableSchema.GetTableData方法的典型用法代码示例。如果您正苦于以下问题:C# TableSchema.GetTableData方法的具体用法?C# TableSchema.GetTableData怎么用?C# TableSchema.GetTableData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TableSchema
的用法示例。
在下文中一共展示了TableSchema.GetTableData方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetEnumItems
private List<DbmlEnum.Item> GetEnumItems(TableSchema tableSchema, DbmlEnum.Enum existingEnum)
{
List<DbmlEnum.Item> itemList = new List<DbmlEnum.Item>();
string primaryKey = tableSchema.PrimaryKey.MemberColumns[0].Name;
string nameColumn = settings.GetEnumNameColumnName(tableSchema);
string descriptionColumn = settings.GetEnumDescriptionColumnName(tableSchema);
DataTable table = tableSchema.GetTableData();
if (table.Rows.Count == 0)
throw new ApplicationException(string.Format(
"Table '{0}' was identified as an enum table but does not contain any rows. Please insert rows into the table or ignore the table.",
tableSchema.FullName));
foreach (DataRow row in table.Rows)
{
long value = Int64.Parse(row[primaryKey].ToString());
DbmlEnum.Item existingValue = existingEnum.Items.Where(v => v.Value == value).FirstOrDefault()
?? new DbmlEnum.Item();
string description = (table.Columns.Contains(descriptionColumn))
? row[descriptionColumn] as String
: null;
itemList.Add(new DbmlEnum.Item
{
Name = StringUtil.ToPascalCase(row[nameColumn].ToString()),
Value = value,
Description = description ?? existingValue.Description,
DataContractMember = existingValue.DataContractMember
});
}
return itemList;
}