2

这是我的 createcustomer 函数,它向调用者返回一个客户对象,getCustomerDetail 返回一个数据表,然后用值填充客户对象属性。问题是每当对象发生变化时,我必须再次修改它,我该如何解决这个问题,以便我只需要更改 Customer 对象并节省我修改整个代码的工作?

  public Objects.Customer createCustomer()
    {
        DataTable dt = Database.Master.Customer.getCustomerDetail(objCustomer.Custcode);

        objCustomer.Billaddress1 = dt.Rows[0]["Billaddress1"].ToString();
        objCustomer.Billaddress2 = dt.Rows[0]["Billaddress2"].ToString();
        objCustomer.Billaddress3 = dt.Rows[0]["Billaddress3"].ToString();
        objCustomer.Billcontact = dt.Rows[0]["Billcontact"].ToString();
        objCustomer.Billfaxno = dt.Rows[0]["Billfaxno"].ToString();
        objCustomer.Billpostalcode = dt.Rows[0]["Billpostalcode"].ToString();
        objCustomer.Billremarks = dt.Rows[0]["Billremarks"].ToString();
        objCustomer.Billtelno = dt.Rows[0]["Billtelno"].ToString();
        objCustomer.Custcode = dt.Rows[0]["Custcode"].ToString();
        objCustomer.Custname = dt.Rows[0]["Custname"].ToString();
        objCustomer.Doout = dt.Rows[0]["Doout"].ToString();
        objCustomer.Douom = dt.Rows[0]["Douom"].ToString();
        objCustomer.Inuom = dt.Rows[0]["Inuom"].ToString();
        objCustomer.Location = dt.Rows[0]["Location"].ToString();
        objCustomer.Outremarks1 = dt.Rows[0]["Outremarks1"].ToString();
        objCustomer.Outremarks2 = dt.Rows[0]["Outremarks2"].ToString();
        objCustomer.Outremarks3 = dt.Rows[0]["Outremarks3"].ToString();
        objCustomer.Pacout = dt.Rows[0]["Pacout"].ToString();
        objCustomer.Pacuom = dt.Rows[0]["Pacuom"].ToString();
        objCustomer.Perout = dt.Rows[0]["Perout"].ToString();
        objCustomer.Peruom = dt.Rows[0]["Peruom"].ToString();
        objCustomer.Shipaddress1 = dt.Rows[0]["Shipaddress1"].ToString();
        objCustomer.Shipaddress2 = dt.Rows[0]["Shipaddress2"].ToString();
        objCustomer.Shipaddress3 = dt.Rows[0]["Shipaddress3"].ToString();
        objCustomer.Shipcontact = dt.Rows[0]["Shipcontact"].ToString();
        objCustomer.Shipfaxno = dt.Rows[0]["Shipfaxno"].ToString();
        objCustomer.Shippostalcode = dt.Rows[0]["Shippostalcode"].ToString();
        objCustomer.Shipremaks = dt.Rows[0]["Shipremaks"].ToString();
        objCustomer.Shiptelno = dt.Rows[0]["BilladdresShiptelnos1"].ToString();
        objCustomer.Shortname = dt.Rows[0]["Shortname"].ToString();


        return objCustomer;
    }
4

2 回答 2

1

一些想法:

于 2012-04-14T02:38:35.140 回答
0

您可以使用自动映射器

AutoMapper.Mapper.CreateMap<IDataReader, Objects.Customer>();
var results = AutoMapper.Mapper.Map<IDataReader, IList<Objects.Customer>>(dt.CreateDataReader());
于 2012-04-14T02:37:43.550 回答