I am new to LINQ and I am a bit confuse on how to write IF ELSE in LINQ.
The current LINQ that I have created is :
lstRecord = (from a in lstPerson
select new GeneralCommonFunctions.MemberDetailSumary
{
AgeGroupId = a.AgeGroup_id!=null? a.AgeGroup_id.Value: 0,
AgeGroupText = a.Agegroup!=null?a.Agegroup.Description: "",
}).ToList();
Now I would like to get the DOB from the list and calculate the current age based on today's date, then categorise it into the age group (the current version is directly get the agegroup from database).
The available age group is :
BELOW 25 (ID is 1)
26-35 (ID is 2)
36-45 (ID is 3)
46-55 (ID is 4)
55 AND ABOVE (ID is 5)
For example, if member DOB is 1990-01-15, he is belongs to agegroup 2. if member DOB is 1970-12-20, he is belongs to agegroup 4.
I am stucked in this coding:
lstRecord = (from a in lstPerson
select new GeneralCommonFunctions.MemberDetailSumary
{
Age = DateTimeUtility.GetCurrentAge(a.Dob),
//I dont know how to continue in this part, my idea is if the age is 0-25, the agegroup_id is 1, if the age is 30, the agegroup_id is 2.
}).ToList();
Is anyone of you can help me with this? Thank you !
UPDATE:
I have an idea of update all the rows using LINQ when button clicked. For example, is user clicked a button, then the system will check every person DOB, then update their agegroup in database.
For example, if person A DOB is 1990-01-01, his/her agegroup will automatically update to 2, if person B DOB is 1970-05-15, his/her agegroup will update to 4.
How to write a linq to update all rows in database? Thank you for your help!