Sunday, June 10, 2018

Looping linq queries?

I have an MVC/C#/Linq logic issue that's been racking my brain.

I have a table for items and their pricing. The simplified table structure is Item, PriceLevel, Price. The PriceLevel is A-G so it would look something like this

Item1, A, 1.00

Item1, B, 2.00

Item1, C. 3.00

etc...

This process repeats for thousands of items. My goal is to have the user be able to pull up a page for the item and have them be able to edit the price for each level. Now, just for the display I was thinking that I could have an item class with itemnumber, pricelevel, and price. Then run a LINQ query to fill the class. Seems reasonable.

OR...

Create the class as ItemNumber, Price_A, Price_B, Price_C.... Run a linq query and do a for each and then a switch on the results. I could use DataAnnotations and change the display name for the Html.DisplayFor. It seems pretty and static and dirty.

Once the user makes the edits and posts the model I run into another wall of getting it all back into the table. 7 individually coded LINQ statements is what it would take to strip the A-G and get it back into the table appropriately.

Surely, this can't be right. Has anyone faced anything like this and can point me in the general direction? The term dictionary is popping out in my head but I'm not sure how to use it in this context. Any help would be appreciated.

Looping linq queries? Click here
  • Blogger Comment
  • Facebook Comment

0 comments:

Post a Comment

The webdev Team