A simple solution is to add .ToList () before your choice (...).
ViewDet = _db.Grp.ToList().Select(gh => new MultiDetailViewModel ...)
Thus, the initial query will go to the database, return with the results, and you can then reprogram them using the select statement for Linq for objects.
But I have to ask why there is no FK relationship between groups and texts and therefore there is an association of entities between the two, allowing you to simply access gh.GrpText and get into a collection of texts lazily loaded (or eagerly loaded using .Include () )
As @Doguhan Uluca notes in the comments, using ToList() is risky as it will cause everything in this table to be fetched into memory. You should use it only in very small collections. The right approach is to fix your database design so that you can query it efficiently.
Ian mercer
source share