Add primary key [Key] to ADO.NET generated table classes

258 Views Asked by At

I'm using the ADO.NET Entity Data Model (EF Designer from database), which will generate the following class from my database table "customer":

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

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

I would like it to add a [Key] attribute to primary key fields on generation, like:

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

How can it be done?

The primary key appears in the .edmx file, but is not added to the customer class

0

There are 0 best solutions below