c# - 将主键 [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
类中
解决方案
推荐阅读
- google-chrome - PWA manifest.json start_url 失败
- google-cloud-platform - 从 gcp 云存储到 bigquery 的数据传输 - 日志显示成功,但 bigquery 表中没有数据
- scala - 无主键列的 Spark jdbc 读取性能调优
- robotframework - 如何使用机器人框架将参数从测试用例传递给关键字?
- python - 如何更改我的熊猫数据框输出格式,例如自动调整列大小
- vba - 如果页尾拆分组,如何将数据组移动到下一页?
- sql-server - 创建参数
- apache-kafka - 为什么 kafka-console-consumer.sh 不使用 --from-beginning 从所有可用日志中返回消息?
- php - 当我当时更新“DB_1.users”表中的任何列时,我想更改“DB_2.all_users”表中的同一列
- spring-boot - Eureka preferIpAddress: true is not working with spring boot 2.1.3 'Greenwich.RELEASE' '