Note that there are some explanatory texts on larger screens.

plurals
  1. POAutomapper and lazy loading with EF and performance
    primarykey
    data
    text
    <p>I have a model like this</p> <pre><code>public class Exam { public int NewsId { get; set; } public string Title { get; set; } public string Description{ get; set; } public string Program{ get; set; } } </code></pre> <p>and a view model like this</p> <pre><code>public class ExamViewModel { public int NewsId { get; set; } public string Title { get; set; } } </code></pre> <p>and I do config Automapper like this</p> <pre><code>AutoMapper.Mapper.CreateMap&lt;Exam, ExamViewModel&gt;(); </code></pre> <p>and in an ActionResult I used Automapper like this:</p> <pre><code> public ActionResult Exam() { var examsDb = db.Exams; IEnumerable&lt;ExamViewModel&gt; examViewModel = AutoMapper.Mapper.Map&lt;IEnumerable&lt;Exam&gt;, IEnumerable&lt;ExamViewModel&gt;&gt;(examsDb); return View(examViewModel); } </code></pre> <p>and in view I loop through it</p> <pre><code> @model IEnumerable&lt;AraParsESOL.ViewModels.ExamViewModel&gt; &lt;ul&gt; @foreach (var e in Model) { &lt;li&gt; @Html.ActionLink(e.Title, "Type", "Exam") &lt;/li&gt; } &lt;/ul&gt; </code></pre> <p>My problem is that: As you can see in the Model There are 4 properties but in viewModel there are only 2 properties.</p> <p>How can i get only those 2 properties in viewModel and not the entire Model?</p> <p>What happens here is that in view after each loop it goes and get the required column from the database but i want only those 2 properties and not going back to database.</p> <p>i can get the database like this db.Exam.ToList(); but it will cause the entire database gets back. i want to use best practices here?</p> <p>i know i can get the data from database by anonymouse type and select command but then what is the use of automapper? what is the best solution here?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload