C#从dataTable填充聚合类

C#从dataTable填充聚合类

本文介绍了使用Linq C#从dataTable填充聚合类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在C#中填充聚合类?

  //   
public class 员工
{
public string 名称{ get ; set ; }
public string 部门{ get ; set ; }
public double 薪资{ get ; set ; }
public 列表< client> client = new < list>< client>();

公共员工(客户objClient)
{
.client.Add(objClient);
}
}

public class 客户
{
public int ID {获得; set ; }
public string 名称{ get ; set ; }
public string 国家{获取; set ; }
public string 地址{ get ; set ; }
}

// 在表单中选择返回DataTable
var ds = cnn.ExecutarSelectDataSet( 选择e.Name,e.Department,e.Salary,e.fk_client,c.Id,c.Name,c.Country,c .Anddess +
来自员工e +
INNER JOIN客户端c +
ON e.fk_client = c.id);

// 我无法填写List< client>物业客户类职员
列表< employee> linqquery =( from dr in ds.Tables [ 员工]。AsEnumerable()
join dr2 in ds.Tables [ Client]。AsEnumerable()$ dr.Field上的b $ b< guid>( fk_client)等于dr2.Field< guid> ( id
select dr)。ToList();
解决方案

How to fill an aggregate class in C #?

//Class
public class Employee
{
    public string Name { get; set; }
    public string Department { get; set; }
    public double Salary { get; set; }
    public List<client> client = new <list><client>();

    Public Employee(Client objClient)
    {
        this.client.Add(objClient);
    }
}

public class Client
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Country { get; set; }
    public string Address { get; set; }
}

//In form a Select returning a DataTable
 var ds= cnn.ExecutarSelectDataSet("select e.Name, e.Department, e.Salary,e.fk_client,c.Id, c.Name,c.Country,c.Anddess" +
                                  "from Employee e" +
                                  "INNER JOIN Client c" +
                                  "ON e.fk_client = c.id");

//I am unable to fill the List <client> Property client Class Employees
List<employee> linqquery = (from dr in ds.Tables["Employee"].AsEnumerable()
    join dr2 in ds.Tables["Client"].AsEnumerable()
    on dr.Field<guid>("fk_client") equals dr2.Field<guid>("id")
     select dr).ToList();
解决方案


这篇关于使用Linq C#从dataTable填充聚合类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 17:49