Populate an Object Model from a data dataTable(C#3.0)

Posted by Newbie on Stack Overflow See other posts from Stack Overflow or by Newbie
Published on 2010-05-08T11:47:46Z Indexed on 2010/05/08 11:58 UTC
Read the original article Hit count: 143

Filed under:

I have a situation I am getting data from some external sources and is populating into the datatable. The data looks like this

DATE        WEEK    FACTOR
3/26/2010   1   RM_GLOBAL_EQUITY
3/26/2010   1   RM_GLOBAL_GROWTH
3/26/2010   2   RM_GLOBAL_VALUE
3/26/2010   2   RM_GLOBAL_SIZE
3/26/2010   2   RM_GLOBAL_MOMENTUM
3/26/2010   3   RM_GLOBAL_HIST_BETA

I have a object model like this

public class FactorReturn
    {       
        public int WeekNo
        {            get; set;        }
        public DateTime WeekDate
        {           get; set;        }
        public Dictionary<string, decimal> FactorCollection
        {            get; set;        }
    }

As can be seen that the Date field is always constant.

And a single(means unique) week can have multiple FACTORS.

i.e. For a date(3/26/2010), for Week No. 1, there are two FACTORS(RM_GLOBAL_EQUITY and RM_GLOBAL_GROWTH).

Similarly,

For a date(3/26/2010), for Week No. 2, there are three FACTORS(RM_GLOBAL_VALUE
, RM_GLOBAL_SIZE  and RM_GLOBAL_MOMENTUM ).

Now we need to populate this data into our object model.

The final output will be

WeekDate: 3/26/2010
    WeekNo : 1
        FactorCollection : RM_GLOBAL_EQUITY
        FactorCollection : RM_GLOBAL_GROWTH
    WeekNo : 2
        FactorCollection : RM_GLOBAL_VALUE
        FactorCollection : RM_GLOBAL_SIZE
        FactorCollection : RM_GLOBAL_MOMENTUM
    WeekNo : 3
        FactorCollection : RM_GLOBAL_HIST_BETA

That is, overall only 1 single collection, where the Factor type will vary depending on week numbers.

I have tried but of useless. Nothing works.

Could you please help me?. I feel it is very tough

I am using C# 3.0

Thanks

© Stack Overflow or respective owner

Related posts about c#3.0