I would like to get records from the database using Dynamic Linq Library NuGet. How can I write query for select parent records along with list of child records. For example there is One-on-Many relationship between Question and Answers table. QuestionID is a Foreign Key column in Answers table.
It is very simple if i give column name in where clause when i am not going to use Dynamic Linq Library NuGet.
var LinQResult=db.Questions
.Include(f=>f.Answers).Where(f=>f.Email=="someEmail").ToList();
I have no question on above query and i can simply render the content on razor views or any web forms.
If i am going to use Dynamic Linq Library NuGet, I have a search criteria in string format like below,
string SearchCreteria = "Email=\"SomeValue\"";
Passing the above dynamic search criteria in where clause below,
var QueryBuilder = (from q in db.Questions
join a in db.Answers on q.QuestionID equals a.QuestionID into answer
from a in answer.DefaultIfEmpty()
select new { q,a}).Distinct().AsQueryable();
var Result = QueryBuilder.Where(SearchCreteria);
How can I convert/add above Result into a strongly typed list below
List<QuestionVM> questionVM=new List<QuestionVM> ();
public class QuestionVM
{
public Question Question { get; set; }
public List<Answer> Answers { get; set; }
}