5

我在使用 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; }
    }
}
4

1 回答 1

3

您没有为实体声明主键。为此,您可以使用 [Key} 属性标记主键列。假设这是 Id 属性,代码如下所示:

[Column("BudgetItemID")]
[Key]
public int Id { get; set; }
于 2012-07-13T03:15:24.163 回答