本文整理汇总了C#中this.AsEnumerable方法的典型用法代码示例。如果您正苦于以下问题:C# this.AsEnumerable方法的具体用法?C# this.AsEnumerable怎么用?C# this.AsEnumerable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类this
的用法示例。
在下文中一共展示了this.AsEnumerable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Upload
public static void Upload(this System.Data.DataTable dt, string tableName)
{
string query = "SELECT * from " + tableName;
using (SqlConnection conn = new SqlConnection(SqlConnStr))
{
using (SqlDataAdapter oda = new SqlDataAdapter())
{
using (SqlCommandBuilder bu = new SqlCommandBuilder())
{
using (SqlBulkCopy bulkcopy = new SqlBulkCopy(conn))
{
oda.SelectCommand = new SqlCommand(query, conn);
bulkcopy.DestinationTableName = "dbo." + tableName;
DataTable dtsql = new DataTable();
oda.Fill(dtsql);
List<DataRow> lst_temp = dt.AsEnumerable().ToList();
foreach (DataRow row in lst_temp)
{
dtsql.ImportRow(row);
}
conn.Open();
bulkcopy.WriteToServer(dtsql);
conn.Close();
}
}
}
}
}
示例2: CalculateSum
public static DataTable CalculateSum(this DataTable source)
{
var query = source.AsEnumerable();
var table = query.CopyToDataTable();
var newRow = table.NewRow();
//Summe Heizperiode
newRow[0] = "Summe Heizperiode";
int cellsCount = table.Columns.Count - 1;
for (int i = 1; i <= cellsCount; i++)
{
newRow[i] = CalcColumnSumme(table, i, true);
}
//Summe Jahr
var newRow2 = table.NewRow();
newRow2[0] = "Summe Jahr";
for (int i = 1; i <= cellsCount; i++)
{
newRow2[i] = CalcColumnSumme(table, i, false);
}
table = GetTableWithMonts(table);
table.Rows.Add(newRow);
table.Rows.Add(newRow2);
return table;
}
示例3: IsEqualTo
public static bool IsEqualTo(this DataTable source, DataTable other)
{
if (other == null)
{
return false;
}
return source.AsEnumerable().SequenceEqual(other.AsEnumerable(), DataRowComparer.Default);
}
示例4: GenerateItems
public static IEnumerable<ListItem> GenerateItems(this DataTable Table, string ValueField, string TextField)
{
IEnumerable<ListItem> Result = new List<ListItem>();
var datos = Table.AsEnumerable();
Result = datos.Select(p => new ListItem { Value = p[ValueField].ToString(), Text = p[TextField].ToString() });
return Result;
}
示例5: AsSelectedList
/// <summary>
/// Get Authors as SelectedList (for Views)
/// </summary>
/// <param name="Authors">List of Athors</param>
/// <param name="currAuthor">Current Author will be selected</param>
/// <returns></returns>
public static List<SelectListItem> AsSelectedList(this IQueryable<Author> Authors, int currAuthor = 0)
{
return (from author in Authors.AsEnumerable()
select new SelectListItem
{
Value = author.Id.ToString(),
Text = author.FirstName + " " + author.LastName,
Selected = author.Id == currAuthor
}).ToList();
}
示例6: ToAMSChannels
public static AMSChannelCollection ToAMSChannels(this IEnumerable<IChannel> channels)
{
channels.NullCheck("channels");
AMSChannelCollection result = new AMSChannelCollection();
channels.AsEnumerable().ForEach(c => result.Add(c.ToAMSChannel()));
return result;
}
示例7: FieldsIn
public static HashSet<Field> FieldsIn (this LispList<PathElement> path)
{
var result = new HashSet<Field> ();
if (path != null) {
foreach (PathElement element in path.AsEnumerable ()) {
Field f;
if (element.TryField (out f))
result.Add (f);
}
}
return result;
}
示例8: AsDynamic
/// <summary>DataTableの各RowをExpandoObjectに変換します。</summary>
public static IEnumerable<dynamic> AsDynamic(this DataTable table)
{
return table.AsEnumerable().Select(x =>
{
IDictionary<string, object> dict = new ExpandoObject();
foreach (DataColumn column in x.Table.Columns)
{
var value = x[column];
if (value is System.DBNull) value = null;
dict.Add(column.ColumnName, value);
}
return (dynamic)dict;
});
}
示例9: AsObservable
public static IObservable<KeyValuePair<string, string>> AsObservable(this IConfiguration configuration) {
return Observable.Create<KeyValuePair<string, string>>(observer => {
var dictionary = configuration.AsEnumerable().ToDictionary(x => x.Key, x => x.Value, StringComparer.OrdinalIgnoreCase);
var token = ChangeToken.OnChange(() => configuration.GetReloadToken(), () => {
var value = (string)null;
foreach(var kvp in configuration.AsEnumerable()) {
if(dictionary.TryGetValue(kvp.Key, out value) && value.Equals(kvp.Value, StringComparison.OrdinalIgnoreCase)) {
continue;
}
else {
dictionary[kvp.Key] = kvp.Value;
observer.OnNext(kvp);
}
}
});
return () => {
observer.OnCompleted();
token.Dispose();
};
});
}
示例10: ToRouteValues
public static IDictionary<string, object> ToRouteValues(
this IDictionary<string, MethodArgumentTestContext> dictionary,
Func<KeyValuePair<string, MethodArgumentTestContext>, bool> filter = null)
{
var result = dictionary.AsEnumerable();
if (filter != null)
{
result = result.Where(filter);
}
return result.ToDictionary(
a => a.Key,
a => a.Value.Value);
}
示例11: ToJsonValidation
public static SimpleModelState ToJsonValidation(this ModelStateDictionary modelState)
{
var v = from m in modelState.AsEnumerable()
from e in m.Value.Errors
select new SimpleError { Key = m.Key, ErrorMessage = e.ErrorMessage };
v = v.ToList();
var pe = v.Where(x => !string.IsNullOrEmpty(x.Key)).ToList();
var me = v.Where(x => string.IsNullOrEmpty(x.Key)).ToList();
return new SimpleModelState
{
IsValid = modelState.IsValid,
PropertyErrors = pe,
ModelErrors = me
};
}
示例12: Sort
public static IQueryable<Message> Sort(this IQueryable<Message> source, MessageSort sortedBy, bool des)
{
if (sortedBy == MessageSort.PublishTime)
{
source = source.OrderBy(m => m.CreateTime);
}
else if (sortedBy == MessageSort.ReadTime)
{
source = source.OrderBy(m => m.ReadTime);
}
if (des)
{
source = source.AsEnumerable().Reverse().AsQueryable();
}
return source;
}
示例13: AsDynamic
/// <summary>
/// DataTableの各RowをExpandoObjectに変換します。
/// </summary>
/// <param name="table"></param>
/// <returns></returns>
public static dynamic AsDynamic(this DataTable table)
{
// return table.AsEnumerable()
var dynamic = table.AsEnumerable()
.Select(row =>
{
IDictionary<string, object> expando = new ExpandoObject();
foreach (DataColumn column in row.Table.Columns)
{
var value = row[column];
if (value is DBNull) { value = null; }
expando.Add(column.ColumnName, value);
}
return (dynamic) expando;
});
return dynamic;
}
示例14: GroupBy
public static DataTable GroupBy(this DataTable inputDataTable, string[] columnNames)
{
var groupedDataTable = new DataTable();
var distinctColumnNames = columnNames.Distinct().ToArray();
foreach (var columnName in distinctColumnNames)
{
groupedDataTable.Columns.Add(columnName, inputDataTable.Columns[columnName].DataType);
}
foreach (
var grouping in
inputDataTable.AsEnumerable()
.GroupBy(r => new NTuple<object>(distinctColumnNames.Select(cn => r[cn]))))
{
var row = groupedDataTable.NewRow();
for (int i = 0; i < distinctColumnNames.Length; i++)
{
row[i] = grouping.Key.Values[i];
}
groupedDataTable.Rows.Add(row);
}
return groupedDataTable;
}
示例15: GetErrors
public static string[] GetErrors(this ModelStateDictionary modelState, string prefix)
{
if (!modelState.IsValid)
{
List<string> errors = new List<string>();
IEnumerable<KeyValuePair<string, ModelState>> states =
prefix.IsNullOrEmpty() ? modelState.AsEnumerable()
: modelState.Where(x => x.Key.StartsWith(prefix + "."));
foreach (var modelStateKvp in states)
{
foreach (var modelError in modelStateKvp.Value.Errors)
{
errors.Add(modelError.ErrorMessage);
}
}
return errors.ToArray();
}
return null;
}