本文介绍了IDataReader连接值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我的IDataReader中的
我在企业库的帮助下从我的存储过程中读取结果。问题是我在不同的表上有两列,它们包含不同的值,但是命名相同,所以当person.AddressID和Address.AddressID不同时,当AddressID返回时,我的AddressID会返回相同的值,因为连接在personID上。



Hello,

in my IDataReader I am reading results from my stored procedure with help of the enterprise library. The problem is I have two columns on different tables that hold different values but are named the same thing, so when I have AddressID coming back with the same value when person.AddressID and Address.AddressID are different as the join is on personID.

public static List<person> ToPersonListFull(this IDataReader dataReader)
    {
        var returnList = new List<person>();
        while (dataReader.Read())
        {
            var Person = new Person()
            {
                PersonID = Int32.Parse(dataReader["PersonID "].ToString()),
                Name = dataReader["Name"].ToString(),
                AddressID = Int32.Parse(dataReader["AddressID"].ToString()),
                Address = new Address ()
                {
                    AddressID = Int32.Parse(dataReader["AddressID "].ToString()),
                    PersonID = Int32.Parse(dataReader["PersonID "].ToString()),
                    Address1 = dataReader["Address1"].ToString(),
                    ZipCode = Int32.Parse(dataReader["ZipCode"].ToString()),

                },


            };
            returnList.Add(Person);
        }
        return returnList;
    }





任何帮助都会很棒!谢谢



Any help would be great! Thank you

推荐答案



这篇关于IDataReader连接值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-12 04:03