日期:2014-05-17  浏览次数:20407 次

MVC3報錯 var movies返回的是空,請我
Movie類
C# code

    public class Movie
    {
        public int rr_id { set; get; }
        public char rr_cat { set; get; }
        public char rr_requsr { set; get; }
        public DateTime rr_crtdat { set; get; }
        public char lusr { set; get; }
        public DateTime ldte { set; get; }

    }
    public class MovieDBContext : DbContext
    {
        public DbSet<Movie> Moviesa { get; set; }
    }


MoviesController控制器
C# code

   public class MoviesController : Controller
    {
        MovieDBContext db = new MovieDBContext();

        public ActionResult Index()
        {
            var movies = from m in db.Moviesa  select m;
            return View(movies.ToList());
        }

    }



Web.config連接數據庫代碼
  <connectionStrings>
  <add name="ApplicationServices"
  connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
  providerName="System.Data.SqlClient" />
  <add name="MovieDBContext"
  connectionString=" Data Source=mis-0825;Initial Catalog=Movies;Persist Security Info=True;User ID=sa;Password=sa "
  providerName="System.Data.SqlClient" />

  </connectionStrings>

報錯:


Line 14: public ActionResult Index()
Line 15: {
Line 16: var movies = from m in db.Moviesa select m;//報錯
Line 17: return View(movies.ToList());
Line 18: }
 


------解决方案--------------------
我记得EntityFramework的连接字符串有一堆
metadata=res://*/Repository.Log.csdl|res://*/Repository.Log.ssdl|res://*/Repository.Log.msl

这种东西的。