Click here to Skip to main content
15,891,409 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a collection of CDs recorded in a db table.
Each one is assigned a GenreID. eg. 1= Classical, 2 = Pop, 3= Folk etc.
Each CD is assigned a number from a sequence for each Genre. This is done manually at the moment.
When I record a new CD,I would like to have the next number in my chosen Genre allocated to an input form in my view.
I would welcome help with the Linq query and with getting the result to the input box within the view.
Kind regards
Jim

What I have tried:

My view currently sends the GenreId to the Controller.
The method has the following Linq:-
<pre>var query =( from DM in c.DiscMain
                        where DM.GenreId==GenreId       
                        orderby DM.DiscNo descending
                        select DM).Take(1);
                        return Json(query);
Posted
Updated 18-Apr-19 14:02pm
Comments
Maciej Los 19-Apr-19 2:31am    
You don't need linq query to get/set GenreId manually! You have to get/set new value on database level.

1 solution

Get the Max() id for a given genre. That's the last one assigned for that genre.
C#
... Where( x => x.genre == z ).Max( x => x.id ).SingleOrDefault();

Increment it by 1 to get the next one to assign.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900