Click here to Skip to main content
15,916,462 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi All,

I have created a stored procedure in sql server which is returning multiple select statements from multiple table. Now I need to map those multiple table's record to a single class. i.e. I have two tables User, Address. Now I have a stored procedure which is returning those table's data

SELECT * FROM USERS
SELECT * FROM ADDRESS

Now I need to bind these two table's record to a Single Class. I do not want to use Datatable. Anyone let me know how to achieve this?
Posted
Comments
imaa2amha 14-Sep-11 4:40am    
if they are related to each other create new VIEW and join them and the create a procedure to select from the view so you can make class to to see both data by join the tow tables to each other . if they are not related to each other can u tell me what is the purpose of doing this

The way I would set this up would be to have an Address class, then a User class that has a property that returns an Address, something like this

C#
class Address
    {
        public string Street { get; set; }
        public string Suburb { get; set; }
        public string City { get; set; }
    }

    class User
    {
        public string FirstName { get; set; }
        public string LastName{get;set}
        public int Age{get;set;}
        public Address CurrentAddress{get;set;}
    }


Then you can populate both classes from one DataReader.

Hope this helps
 
Share this answer
 
Hi, Thanks for your repaly..but I am not using datareader. I have mapped the stored procedure with the Linq, which return the List of records.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900