私はオンラインショップmvc webを作っています。カテゴリー用のテーブルを作成してデータで埋めて、製品用のテーブルを作成してデータで埋めました。ウェブ(注上でそれらをプレビューするデータベース:。その後、カテゴリを押した後、我々はこれらのカテゴリの製品を持つことになり、それがカテゴリに私たちを取るだろう、私はウェブ上の店舗に押したい これは私のストアコントローラです:SQLサーバーへの接続文字列MVC C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MVCOnlineShop.Models;
namespace MVCOnlineShop.Controllers
{
public class StoreController : Controller
{
OnlineStoreEntities storeDB = new OnlineStoreEntities();
//
// GET: /Store/
public ActionResult Index()
{
var Categories = storeDB.Categories.ToList();
return View(Categories);
}
//
// GET: /Store/Browse
public ActionResult Browse(string Category)
{
// Retrieve Category and its Associated Products from database
var CategoryModel = storeDB.Categories.Include("Products")
.Single(g => g.Name == Category);
return View(CategoryModel);
}
//
// GET: /Store/Details
public ActionResult Details(int id)
{
var Product = storeDB.Products.Find(id);
return View(Product);
}
//
// GET: /Store/Browse?Category=Games
}
}
SQLサーバーへの正しい接続文字列を教えてください
エンティティフレームワークを正しく使用している必要がありますか?あなたは接続とすべてを提供しています。私はあなたが接続について心配する必要はありませんね。 –
これらのデータをテーブルに接続するために使用するコードはありますか? –
いいえプロジェクトにedmxを追加すると、接続文字列を入力してDBに接続すると、プロジェクト内にエンティティ(テーブル)を追加できます。 –