【发布时间】:2013-12-28 02:05:34
【问题描述】:
当我从控制器访问模型的数据时。我收到此错误EntitySet 'Department' 基于没有定义键的类型'Admin'。我正在将 MVC5 与 Visual stdio 2013 RC 一起使用。
deptID (Primary key), deptName, Description : 都是Department表的列名。
desgID(Primary key)、desgName、description:都是Designation表的列名。
目标:- 我想在视图页面上创建一个 deptName 或 desgName 对话框,但现在我想解决这些问题。
我指的是这些链接:- EntityType 'Category' has no key defined. Define the key for this EntityType
ASP.NET MVC 3 EntityType has no key defined
但根据这些链接。我正在尝试将 [Key] 与我的主键列一起使用,但它在 mvc5 中没有提示。
型号:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
namespace mvcAppraisalSystem.Models
{
public class Admin
{
public int deptID { get; set; }
public string deptName { get; set; }
public string Description { get; set; }
public int desgID { get; set; }
public string desgName { get; set; }
public string description { get; set; }
}
public class AdminDBContext : DbContext
{
public DbSet<Admin> Department { get; set; }
public DbSet<Admin> Designation { get; set; }
}
}
【问题讨论】:
标签: c# entity-framework visual-studio-2013