首页 > 解决方案 > 将主键 [Key] 添加到 ADO.NET 生成的表类

问题描述

我正在使用 ADO.NET 实体数据模型(数据库中的 EF 设计器),它将从我的数据库表“客户”中生成以下类:

namespace WebApp1.Models
{
    using System;
    using System.Collections.Generic;

    public partial class customer
    {
        public int id { get; set; }
        public string name { get; set; }
    }
}

我希望它在生成时向主键字段添加 [Key] 属性,例如:

[System.ComponentModel.DataAnnotations.Key]
public int id { get; set; }

怎么做到呢?

主键出现在 .edmx 文件中,但未添加到customer类中

标签: c#primary-keycode-generationado.net-entity-data-model

解决方案


推荐阅读