Hello guys wanna ask help because I don't understand how to create database that I can use using MASSIVE.CS in ASP.NET MVC 3.
Im stuck in figuring out how I can implement this MASSIVE class to my MVC project and how connection string connects in northwind database. I only have this tutorial https://github.com/robconery/massive but I'm still having problems understanding.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MovieMassive.Models;
namespace MovieMassive.Controllers
{
public class MoviesController : Controller
{
MovieTable dbMovies = new MovieTable();
public ActionResult Index()
{
dbMovies.Query("SELECT * FROM MovieTable");
return View(dbMovies);
}
public ActionResult Add() {
return View();
}
}
}
Connection string:
<add name="MyConnectionString" connectionString="data source=|DataDirectory|MyDatabase.sdf" providerName="System.Data.SqlServerCe.4.0"/>
MovieTable Class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Massive;
namespace MovieMassive.Models
{
public class MovieTable : DynamicModel
{
public MovieTable() : base("movieMassive", "MovieTable", "ID") { }
}
}
Okay here's what I want, Can you help me how to run correctly the View Index.cshtml
. The properties are not there yet. because don't know hot to implement it with database... Any help will be greatly appreciated..
@model IEnumerable<MovieMassive.Models.MovieTable>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th>Title</th>
<th>ReleaseDate</th>
<th>Genre</th>
<th>Price</th>
<th>Rating</th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Title)
</td>
<td>
@Html.DisplayFor(modelItem => item.ReleaseDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.Genre)
</td>
<td>
@Html.DisplayFor(modelItem => item.Price)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
@Html.ActionLink("Details", "Details", new { id=item.ID }) |
@Html.ActionLink("Delete", "Delete", new { id=item.ID })
</td>
</tr>
}
</table>
I need this one to run correctly to create a basic CRUD using massive. Thanks in advance..
Update to OP comment after code was updated into question
Jed, change your MoviesController to this
Visit TekPub.com, watch the MVC 2 vids (because they're free) as Rob Conery shows you how to implement the Massive file into an MVC app
Here's the direct link
ASP.NET MVC Concepts - free
Rob's Massive.cs file is basically an ORM (Object Relational Mapping) tool that queries your datastore for tables and uses them as objects in your application.
Implementing it is easy. You need:
ConnectionString in your web.config that points to your database. Here's a sample SQL connection string:
If you are using something other than MS SQL you can visit connectionstrings.com for your specific platform
NOTE - most real world applications are comprised of a UI project, a business logic layer and a data access layer. If you are using an N-Tier solution like this, then the Massive.cs file should go into your DAL.
Usage
To use massive in your app just do something like this: I'm using a simple example of a single project MVC app and not separating layers.
Again, this is not the strictest usage. You should learn all about using the MVC pattern and how to structure your solution/application into the correct design. Normally you would use a ViewModel that had properties of
Product
and then you would map theproducts
returned from the Massive call totable.All();
to your ViewModelThis was a simple crash course, hope it helps someone :-)