c# - Data Transfer Objects and Reporting -


i have these scenario:

//this class maps "item" table in database public class item {    public int itemid { get; set;}    public string itemname { get; set; }    public int quantity { get; set; } }  //items record returned database list     list<item> items = itemdao.getitems(); 

i want generate report include aggregate values (from query/stored procedure)

itemid| itemname | qty | qtysoldthismonth | qtysoldthisyr ----------------------------------------------------------- 123   | vit. c   |  20 |   55             |    400 239   | maloxin  |  25 |   12             |    210 

the item class not have these fields have been easier datatable have varying number of columns using list

please, how go this

you can create dto aggregated view , use in reports.

a little more general solution specific dto each view create dto reports on item , use collection of fields instead of class properties store aggregate values in dto.

for instance:

 class aggregatedreportfield {      public string fieldname { get; set; }      public decimal fieldvalue { get; set; }  }   class itemreportdto {       public dictionary<string, aggregatedreportfield> reportfields { get; private set; }       public itemreportdto()      {          reportfields = new dictionary<string, aggregatedreportfield>();      }       public void add(aggregatedreportfield field)      {          if (!reportfields.containskey(fieldl.fieldname))               reportfields.add(field.fieldname, field);      }  } 

in dao, first values database, create aggregatedreportfield instances each value , add them name dto. in report, have refer aggregated values dto.reportfields["somevalue"].fieldvalue.

the code above example , contains few bad practices (exposed dictionary<>).


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -