2011-06-02 202 views
2

enter image description here我正在使用mvc3在.net 4.0中设计一个项目。我使用了两个属性namefname(父名)。数据存储在哪里?

我的控制器类:

loginController.cs

using System; 
using System.Collections.Generic; 
using System.Data; 
using System.Data.Entity; 
using System.Linq; 
using System.Web; 
using System.Web.Mvc; 
using MvcMovie.Models; 

namespace MvcMovie.Controllers 
{ 
    public class loginController : Controller 
    { 
     private logindata db = new logindata(); 

     // 
     // GET: /login/ 

     public ViewResult Index() 
     { 
      return View(db.loginobj.ToList()); 
     } 

     // 
     // GET: /login/Details/5 

     public ViewResult Details(int id) 
     { 
      // login login = db.loginobj.Find(id); 
      login login = db.loginobj.Find(2) ; 
      return View(login); 
     } 

     // 
     // GET: /login/Create 

     public ActionResult Create() 
     { 
      return View(); 
     } 

     // 
     // POST: /login/Create 

     [HttpPost] 
     public ActionResult Create(login login) 
     { 
      if (ModelState.IsValid) 
      { 
       db.loginobj.Add(login); 
       db.SaveChanges(); 
       return RedirectToAction("Index"); 
      } 

      return View(login); 
     } 

     // 
     // GET: /login/Edit/5 

     protected override void Dispose(bool disposing) 
     { 
      db.Dispose(); 
      base.Dispose(disposing); 
     } 
    } 
} 

模型类

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Data.Entity; 
login.cs 

namespace MvcMovie.Models 
{ 
    public class login 
    { 
     public int ID { get; set; } 
     public string name{get; set;} 
     public string fname { get; set; } 
    } 
    public class logindata : DbContext 
    { 
     public DbSet<login> loginobj { get; set; } 
    } 
} 

view.cshtml

@model IEnumerable<MvcMovie.Models.login> 

@{ 
    ViewBag.Title = "Index"; 
} 

<h2>Index</h2> 

<p> 
    @Html.ActionLink("Create New", "Create") 
</p> 
<table> 
    <tr> 
     <th> 
      name 
     </th> 
     <th> 
      fname 
     </th> 
     <th></th> 
    </tr> 

@foreach (var item in Model) { 
    <tr> 
     <td> 
      @Html.DisplayFor(modelItem => item.name) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.fname) 
     </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> 

我想问的是其中存储的数据这是由我创建?意味着我如何看到由我完成的条目表?

只要我点击.sdf文件,然后出现如下图所示的问题,我该如何解决这个问题。我应该安装一些东西。我安装了Visual Studio 2010和SQL Server 2008

+1

Pushpendra - 无需三倍复制相同的注释:)一个简单的谷歌搜索“这不是一个有效的SQL Server Compact数据库文件或文件版本不受当前SQL Server Compact Engine支持“作为_very first_结果将我们带入解决方案:http://stackoverflow.com/questions/4070860/sql-compact-4-0-cant-open-read-sdf -file – 2011-06-02 05:41:35

回答

4

可能您正在使用Microsoft SQL CE来存储您的应用程序数据。如果是这种情况,请查看解决方案资源管理器中的App_Data文件夹。你应该看到一个扩展名为.sdf的文件。只需确保在解决方案资源管理器中选择显示所有文件图标。更多详情here

enter image description here

enter image description here

+0

先生,无论何时我点击.sdf文件,都会出现此错误“这不是有效的SQL Server Compact数据库文件,或者当前的SQL Server Compact Engine不支持此文件版本“请建议我该怎么做。” – 2011-06-02 02:29:34

+0

选中此项:http://stackoverflow.com/questions/4070860/sql-compact-4-0-cant-open-read-sdf-file - 所以,我认为您必须安装Visual Studio SP1才能在Visual Studio中获得对SQL CE 4的工具支持,请在此处下载它:http://www.microsoft.com/downloads/en/details.aspx?FamilyID=75568aa6-8107-475d-948a -ef22627e57a5 – 2011-06-02 02:32:38

0

它看起来像它通过

私人logindata DB做=新 logindata();

你有详细的部分吗?

+0

先生,无论何时单击.sdf文件,都会发生此错误“这不是有效的SQL Server Compact数据库文件,或者当前SQL Server Compact Engine不支持此文件版本。”请告诉我该怎么做。 – 2011-06-02 02:34:14

0

logindata DBContext看起来像它是由实体框架创建的。这是指向某个数据库的地方,那个数据库就是你要去查找数据的地方。您可以在web.config中查找具有数据库信息的连接字符串,或者您的项目中有一个.edmx文件,可以打开该文件并查看其指向的内容。

+0

先生,只要我点击.sdf文件,就会出现此错误“这不是有效的SQL Server Compact数据库文件,或者当前SQL Server Compact Engine不支持此文件版本。“请建议我该怎么办?” – 2011-06-02 02:33:40