linq to entities - Access entity array by index c# -


i have table represents matrix:

custtype  discountgroup1 discountgroup2 discountgroup3 wholesale        32           10               15   retail           10           15               0  

all stock items have corresponding discount group code 1, 2 or 3.

at time of invoicing want lookup discount customer type gets on item(s) being invoiced.

the table needs able grow include new customer types , new discount groups nothing can hardcoded.

i figured pull data array select column index getting stumped entities being intelligent...

var disc = (from d in context.custdiscountgroups                     d.custtype == wholesale                     select d).toarray();  

i can access columns name ie: disc[0].discountgroup1

if try disc[0,1] error saying wrong number of indices inside.

what missing? feel ridiculously fundamental. other thought naming columns 1, 2, 3 etc , building sql select string can use variable denote column name.

the database in design stages table(s) can remade in way needed, i'm struggling head wrapped round way approach problem.

your entity custdiscountgroups having properties custtype, discountgroup1, discountgroup2, discountgroup3 , query return array of custdiscountgroups cant access [0,1] there no 2d array

if need access first item can disc[0] can of properties of discount group name of property.

disc[0].custtype, disc[0].discountgroup1, disc[0].discountgroup2, disc[0].discountgroup3

if want array of array property value using reflection below

var disc = context.custdiscountgroups.where(c=>c.custtype == wholesale)              .select(v=>typeof(custdiscountgroups)                          .getfields(system.reflection.bindingflags.public)                           .select(f=>f.getvalue(v)).toarray())               .toarray();  var disc = context.custdiscountgroups.where(c=>c.custtype == wholesale)              .select(v=>typeof(custdiscountgroups)                          .getproperties()                           .select(f=>f.getvalue(v,null)).toarray()).toarray(); 

now can access values disc[0][1]

please note: haven't compiled , tested above code, please idea , change want


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -