With a plain connection to SQL Server, you can specify what columns to return in a simple SELECT statement.
With EF:
Dim who = context.Doctors.Find(3) ' Primary key is an integer
The above returns all data that entity has… BUT… I would only like to do what you can with SQL and get only what I need.
Doing this:
Dim who= (From d In contect.Doctors
Where d.Regeneration = 3
Select New Doctor With {.Actor = d.Actor}).Single
Gives me this error:
The entity or complex type XXXXX cannot be constructed in a LINQ to Entities query.
So… How do I return only selected data from only one entity?
The best way to do this is by setting the wanted properties in ViewModel “or DTO if you’re dealing with upper levels”
Then as your example the ViewModel will be:
then the query will be:
Sorry i wrote the code with C# but i think the idea is clear 🙂