OL.DemoCore/OL.DemoCore.Utilities/DataTableHelper.cs
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Text;
namespace OL.DemoCore.Utilities
{
/// <summary>
/// DataTable查询的封装类。
/// </summary>
public static class DataTableHelper
{
/// <summary>
/// 执行查询DataTable
/// </summary>
/// <param name="DataTable">table</param>
/// <param name="where">where子语句</param>
/// <param name="args">参数</param>
/// <returns></returns>
public static DataRow[] Query(this DataTable table, string where, params object[] args)
{
return table.Select(string.Format(where, args));
}
/// <summary>
/// DataTable转换为实体对象
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="table"></param>
/// <returns></returns>
public static T GetEntity<T>(DataTable table) where T : new()
{
T entity = new T();
foreach (DataRow row in table.Rows)
{
foreach (var item in entity.GetType().GetProperties())
{
if (row.Table.Columns.Contains(item.Name))
{
if (DBNull.Value != row[item.Name])
{
item.SetValue(entity, Convert.ChangeType(row[item.Name], item.PropertyType), null);
}
}
}
}
return entity;
}
/// <summary>
/// DataTable转换为实体对象集合
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="table"></param>
/// <returns></returns>
public static List<T> GetEntities<T>(DataTable table) where T : new()
后面还有 57 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
