大家好,想寻求帮助,因为我不明白如何在 ASP.NET MVC 3 中使用 MASSIVE.CS 创建可以使用的数据库。
我一直在弄清楚如何在我的 MVC 项目中实现这个 MASSIVE 类,以及连接字符串如何在北风数据库中连接。我只有本教程 https://github.com/robconery/massive但我仍然无法理解。
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();
}
}
}
连接字符串:
<add name="MyConnectionString" connectionString="data source=|DataDirectory|MyDatabase.sdf" providerName="System.Data.SqlServerCe.4.0"/>
电影表类:
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") { }
}
}
好的,这就是我想要的,你能帮我如何正确运行 View 吗Index.cshtml
?属性还没有。因为不知道用数据库来实现它......任何帮助将不胜感激......
@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>
我需要这个正确运行以使用大量创建基本 CRUD。提前致谢..