使用EF5时遇到此错误消息。想知道是否有人有这个答案。
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Budget.Data
{
[Table("BudgetItems")]
public class BudgetItemRepository
{
[Column("MdaCode")]
public int MDACode { get; set; }
[Column("PersonalCost")]
public double PersonnelCost { get; set; }
[Column("OverheadCost")]
public double OverheadCost { get; set; }
[Column("RecurrentCost")]
public int RecurrentCost { get; set; }
[Column("CapitalCost")]
public double Capital { get; set; }
public double Allocation { get; set; }
[Column("BudgetYear")]
public String BudgetYear { get; set; }
[Column("RecordCreatedDate")]
public DateTime DateCreated { get; set; }
[Column("RecordLastModifiedDate")]
public DateTime LastModifiedDate { get; set; }
public virtual IList<BudgetItemRepository> budgetitems { get; set; }
public virtual IList<BudgetLineItemRepository> budgetlineitems { get; set; }
[Column("BudgetItemID")]
public int Id { get; set; }
}
}
答案 0 :(得分:3)
您没有为实体声明主键。您可以通过使用[Key}属性标记主键列来完成此操作。假设这是Id属性,代码如下:
[Column("BudgetItemID")]
[Key]
public int Id { get; set; }