I'm using EF with database first approach.
I would like to add attribute to the generated code to mark property as primary key / foreign key when it's the case.
For example, if I have a table User
in my database
CREATE TABLE User
(
Id int PRIMARY KEY
);
I would like my generated code to include an attribute that indicate that Id
is the primary key.
public partial class User
{
[PrimaryKey]
public int Id { get; set; }
}
How could I do that?
EDIT : I know about T4 template, I just don't know where to start to modify that file.
I ran into the same problem. The template file you are looking for appears in the Solution Explorer (in VS2013) as:
YourDataModelName.tt
You can modify it to add the [Key]
attributes to the generated code by following:
Finding a property is Primary Key in POCO Template t4 generator