Question

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..

Was it helpful?

Solution

Update to OP comment after code was updated into question

Jed, change your MoviesController to this

public class MoviesController : Controller
{
    public ActionResult Index()
    {
        MovieTable dbMovies = new MovieTable();
        dbMovies.All();
        return View(dbMovies);
    }
    ...
}

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:

    <connectionStrings>
        <add name="MyConnectionString" 
             connectionString="Data Source=DNSServerName;Initial Catalog=DatabaseName;user id=Username;password=Password" 
             providerName="System.Data.SqlClient" />
    </connectionStrings>
    

If you are using something other than MS SQL you can visit connectionstrings.com for your specific platform

  • Drop the Massive.cs file downloaded from GitHub into your application. How your solution is divided will make a difference as to where you add the file. If you are using only one project in your ASP.NET MVC app then you can just add it into the project root, or create a folder for it. Rob uses a folder called Infrastructure if I remember correctly.

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.

  • Your ready to go, that's all there is to implementing Massive!

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.

public ActionResult Index() {
    var table = new Products();
    var products = table.All();
    return View(products);
}

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 the products returned from the Massive call to table.All(); to your ViewModel

This was a simple crash course, hope it helps someone :-)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top