asp.net-mvc - 从 SQL 数据库创建
问题描述
我的问题是添加创建页面时,这是从哪里来的?db.AddToMovies(newMovie) - 它给出了一个构建错误(下面的控制器代码)?
这是从 Visual Studio 2019 列出、创建和编辑 SQL 表的最佳方式吗?
谢谢, EB
我已经在控制器页面上添加了它。那是SP还是数据库中的东西?db.AddToEmployees(newEmployee); 正在给出问题。这不是我试图自定义的代码:
IntranetEntities db = new IntranetEntities();
public ActionResult Employees()
{
var employees = from m in db.Employees
select m;
return View(employees.ToList());
}
// GET: Employees/Details/5
public ActionResult Details(int id)
{
return View();
}
// GET: Employees/Create
public ActionResult Create()
{
return View();
}
// POST: Employees/Create
[HttpPost]
public ActionResult Create(Employee newEmployee)
{
if (ModelState.IsValid)
{
db.Employees(newEmployee);
db.SaveChanges();
return RedirectToAction("Employees");
}
else
{
return View(newEmployee);
}
}
解决方案
你可以去上一页,它声明MoviesEntities db = new MoviesEntities();
public class MoviesController : Controller
{
MoviesEntities db = new MoviesEntities();
public ActionResult Index()
{
var movies = from m in db.Movies
where m.ReleaseDate > new DateTime(1984, 6, 1)
select m;
return View(movies.ToList());
}
}
更新:
AddToMovies
可能是数据库中的存储过程,但我在 MSDN 示例中也找不到它。
你可以通过改变来解决
db.AddToMovies(newMovie)
至
_db.Movies.Add(newMovie)
推荐阅读
- android - MediaPlayer,Android:一段时间后,即使事件没有发生,事件处理程序也会自动触发
- javascript - 用 Javascript 让动物在屏幕上运行
- node.js - MongoDB Mongoose:使用“_id”属性查询子文档不起作用
- excel - 将数据从一个工作表复制到另一个工作表不起作用
- ruby-on-rails-4 - 安装 mysql2 时出错:错误:无法构建 gem 原生扩展
- c# - Asp.net 托管了多个 blazor 应用程序
- python - 如何使用 Python 和 Matplotlib 对多边形(由数组定义)进行动画处理
- javascript - 加载时调用上传处理程序的 Jquery 文件上传
- xml - windows命令在xml文件的父标签中查找子标签的组合
- java - android的webview显示空白屏幕