c# - Create a dictionary of a model? -


it's quite hard me explain this, give go.

objective:

create linq query return dictionary of data. must dictionary of model using.

view model:

public class valuebysupplierandclaimtypeviewmodel : reportviewmodel {     public iqueryable<valuebysupplierandclaimtypemodel> reportdata {get; set; }     public totalvaluebysupplierandclaimtypemodel reporttotaldata { get; set; }     public dictionary<string, decimal> dictionarydata { get; set; }      public string output { get; set; } } 

interface:

dictionary<string, decimal> dictdata;  totalvaluebysupplierandclaimtypemodel gettotalvaluebysupplierandclaimtype(     int clientid, int reviewperiodid, int statuscategoryid); 

sql repository:

public totalvaluebysupplierandclaimtypemodel gettotalvaluebysupplierandclaimtype(int clientid, int reviewperiodid, int statuscategoryid) {     var rt =         this.getvaluebysupplierandclaimtype(clientid, reviewperiodid, statuscategoryid);      totalvaluebysupplierandclaimtypemodel x = new totalvaluebysupplierandclaimtypemodel()     {         normaltotal = rt.sum(c=>c.normal) ?? 0,         querytotal = rt.sum( c => c.query) ?? 0,         strongtotal = rt.sum( c => c.strong) ?? 0     };      return x; } 

i'm not sure how this. can help?

i have function converts object dictionary. gets properties of class, dictionary's keys. may can modify meet needs:

    public dictionary<string, object> convertclasstodict(object classtoconvert)     {         dictionary<string, object> result = new dictionary<string, object>();         propertyinfo[] properties = classtoconvert.gettype().getproperties();         list<string> propertiesnames = properties.select(p => p.name).tolist();         foreach (var propname in propertiesnames)         {             propertyinfo property = properties.first(srcprop => srcprop.name == propname);             var value = property.getvalue(classtoconvert, null);             result.add(propname, value);         }          return result;     } 

the argument classtoconvert, instance of class.


Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -