//---------------------------------------------------------------------
// <copyright file="FormartPropty.cs" company="RichCn INC">//
// Information Contained Herein is Proprietary and Confidential.
// Author: ethan(neumik@163.com)
// </copyright>
// <summary>
// 数据动态实体化处理类
// 开发环境:VS2008
// 注意事项:定义的实体类的属性名称 必须与数据库字段名一致 否则无法正常使用,可用LINQ TO SQL 或者动软生成器动态生成实体类
// </summary>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Reflection;
namespace KKBuy.DAO
{
public class FormartPropty<T>
{
public T obj;
public FormartPropty(T obj, DataRow row)
{
Type type = typeof(T);
var props = type.GetProperties();
foreach (var item in props)
{
///如果DataRow里也包括此列
&n

这是一个C#代码示例,展示如何动态地将DataRow的数据绑定到自定义实体类中。通过使用反射,代码遍历DataRow的所有列,并根据列名匹配实体类的属性,将值进行相应的类型转换后赋值。适用场景是当实体类属性名与数据库字段名一致时。
最低0.47元/天 解锁文章
4371

被折叠的 条评论
为什么被折叠?



