相关疑难解决方法(0)

EntityType没有键定义错误

控制器:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplication1.Models;
using System.ComponentModel.DataAnnotations.Schema;

namespace MvcApplication1.Controllers
{
    public class studentsController : Controller
    {
        //
        // GET: /students/

        public ActionResult details()
        {
            int id = 16;
            studentContext std = new studentContext();
           student first = std.details.Single(m => m.RollNo == id);
            return View(first);
        }

    }
}
Run Code Online (Sandbox Code Playgroud)

DbContext模型:

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

namespace MvcApplication1.Models
{
    public class studentContext : DbContext
    {
        public DbSet<student> details { get; set; …
Run Code Online (Sandbox Code Playgroud)

.net c# entity-framework

137
推荐指数
8
解决办法
25万
查看次数

标签 统计

.net ×1

c# ×1

entity-framework ×1