大家好,我不知道如何在MASSIVE.CS 3中使用ASP.NET创建数据库,所以想要寻求帮助。
我一直在弄清楚如何将这个庞大的类实现到我的MVC项目中,以及连接字符串如何在northwind数据库中连接。我只有本教程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();
}
}
}连接字符串:
MovieTable类:
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") { }
}
}好的,这是我想要的,你能帮我正确地运行视图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使用大规模。提前谢谢..。
发布于 2012-05-28 00:01:34
在代码被更新为问题后更新到OP注释
杰德,把你的MoviesController改为这个
public class MoviesController : Controller
{
public ActionResult Index()
{
MovieTable dbMovies = new MovieTable();
dbMovies.All();
return View(dbMovies);
}
...
}访问TekPub.com,查看mvv2vid(因为它们是免费的),因为Rob Conery向您展示了如何将大量文件实现到MVC应用程序中。
这是直接链接
ASP.NET MVC概念-免费
Rob的Massive.cs文件基本上是一个ORM (对象关系映射)工具,它查询数据存储中的表,并将它们作为应用程序中的对象使用。
实施起来很容易。你需要:
如果使用的是MS以外的其他内容,则可以访问特定平台的connectionstrings.com。
注:大多数实际应用程序由UI项目、业务逻辑层和数据访问层组成。如果您使用的是这样的N层解决方案,那么Massive.cs文件应该进入DAL。
用法
要在应用程序中使用大型应用程序,只需这样做:我使用的是一个项目MVC应用程序的简单示例,而不是分层。
public ActionResult Index() {
var table = new Products();
var products = table.All();
return View(products);
}同样,这也不是最严格的用法。您应该学习如何使用MVC模式,以及如何将您的解决方案/应用程序构造成正确的设计。通常,您将使用具有Product属性的Product,然后将从对table.All();的大规模调用中返回的products映射到ViewModel。
这是一个简单的速成班,希望它能帮助别人:-)
https://stackoverflow.com/questions/10778103
复制相似问题