My problem now is that the hard coded data is not being populated.
And I'd like to know why.
In this class - BookInitializer, the author has hard-coded an Author name Jamie Munro:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using BootstrapIntroduction.Models;
- using System.Data.Entity;
- namespace BootstrapIntroduction.DAL
- {
- public class BookInitializer : DropCreateDatabaseIfModelChanges
- {
- protected override void Seed(BookContext context)
- {
- var author = new Author
- {
- Biography = "...",
- FirstName = "Jamie",
- LastName = "Munro"
- };
- var books = new List
- {
- new Book {
- Author = author,
- Description = "...",
- ImageUrl = "http://ecx.images-amazon.com/images/I/51T%2BWt430bL._AA160_.jpg",
- Isbn = "1491914319",
- Synopsis = "...",
- Title = "Knockout.js: Building Dynamic Client-Side Web Applications"
- },
- new Book {
- Author = author,
- Description = "...",
- ImageUrl = "http://ecx.images-amazon.com/images/I/51AkFkNeUxL._AA160_.jpg",
- Isbn = "1449319548",
- Synopsis = "...",
- Title = "20 Recipes for Programming PhoneGap: Cross-Platform Mobile Development for Android and iPhone"
- },
- new Book {
- Author = author,
- Description = "...",
- ImageUrl = "http://ecx.images-amazon.com/images/I/51LpqnDq8-L._AA160_.jpg",
- Isbn = "1449309860",
- Synopsis = "...",
- Title = "20 Recipes for Programming MVC 3: Faster, Smarter Web Development"
- },
- new Book {
- Author = author,
- Description = "...",
- ImageUrl = "http://ecx.images-amazon.com/images/I/41JC54HEroL._AA160_.jpg",
- Isbn = "1460954394",
- Synopsis = "...",
- Title = "Rapid Application Development With CakePHP"
- }
- };
- books.ForEach(b => context.Books.Add(b));
- context.SaveChanges();
- }
- }
- }
-
- @model IEnumerable
- @{
- ViewBag.Title = "Authors";
- }
Authors
- @Html.ActionLink("Create New", "Create")
class="table table-bordered table-striped">
@Html.DisplayNameFor(model => model.FirstName) @Html.DisplayNameFor(model => model.LastName) @Html.DisplayNameFor(model => model.Biography) Actions - "foreach: authors">
"text: FirstName"> "text: LastName"> - "attr: {href: '@Url.Action("Details")/' + Id }" class="btn btn-info">Details
- "attr: {href: '@Url.Action("Edit")/' + Id }" class="btn btn-primary">Edit
- "attr: {href: '@Url.Action("Delete")/' + Id }" class="btn btn-danger">Delete
- @section Scripts {
- }
Rajeev PunhaniPosted Jul 10, 2016, 11:17 PM
If the above solution is helpful then,accept the answer.
Bikesh SrivastavaPosted Jul 10, 2016, 10:53 PM
you are doing correct .
Tangara GPosted Jul 9, 2016, 6:40 AM
Bikesh SrivastavaPosted Jul 9, 2016, 1:44 AM