I searched for similar issues but could not succeed to find any. I'm using the linq select query to fetch some object from the database to collection of an object named "AudioBookDTO". This object has many properties which is clear in following code snippet.
from a in _unitOfWork.AudiobooksViewRepository.GetAll()
where a.EntityTitle.Replace(" ", "").Contains(input.Replace(" ", ""))
group a by new { a.Title, a.Identifier, a.AudioBookId, a.RecordVersion, a.Slug, a.EntityTitle } into grp
select new AudioBookDTO
{
Title = grp.Key.Title,
Identifier = grp.Key.Identifier,
AudioBookId = grp.Key.AudioBookId,
RowVersion = grp.Key.RecordVersion,
Slug = grp.Key.Slug,
HitObject =
(grp.Min(a => a.EntityType) == 2) ? grp.Key.EntityTitle + " (Author)" :
(grp.Min(a => a.EntityType) == 3) ? grp.Key.EntityTitle + " (Translator)" :
(grp.Min(a => a.EntityType) == 4) ? grp.Key.EntityTitle + " (Narrator)" :
(grp.Min(a => a.EntityType) == 5) ? grp.Key.EntityTitle + " (Genre)" :
(grp.Min(a => a.EntityType) == 6) ? grp.Key.EntityTitle + " (Publisher)" :
null,
HitObjectType = grp.Min(a => a.EntityType),
Weight = (grp.Min(a => a.EntityType) == 2) ? 100 : 90,
}).OrderBy(a => a.HitObjectType);
"input" is the keyword which I'm using to search in database. The problem is that all properties in the object will be assigned well except "Weight" that I'm assigning based on a condintion. Let me make it clear that even if I say "Weight = 100", the final result will not have the value that I assigned and will take 0.
Another tip is that the AudiobooksViewRepository is a View which I have defined in the database and has these columns in result: Title, Identifier, AudiobookId, RecordVersion, Slug, EntityType, EntityTitle.
Furthermore, I'm using service controller and the query will not run in the service because OData is handling the pagination. So, doing something like ToList() is not possible due to pagination that is doing the job in the controller layer. (Yes, this is WebAPI)
What is the problem that the "Weight" does not take any value? Thanks in advance