EF6 > Generate code that uses the Column, Key attributes

Posts   
 
    
costa_b
User
Posts: 3
Joined: 25-May-2017
# Posted on: 25-May-2017 19:24:05   

Is it possible?

Example:

  [Table("Applicant", Schema = "dbo")]
    public class Applicant
    {

        [Key]
        public int ApplicantID { get; set; }
        public int ProfileID { get; set; }
        [StringLength(50)]
        public string Name { get; set; }
   }

I inherited a project where the coding was done like that.

Thanks

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 26-May-2017 07:23:43   

Hi,

Actually you can add additional attributes to an entity, field, etc. Do this:

  1. Go to Project -> Settings -> CodeGeneration -> Additional Attributes
  2. In Element Type select 'NormalField'
  3. Add an attribute, put Key in attribute definition
  4. Put a rule that says that it should be emitted when the field is part of the primary key. (I attached a couple of screenshots.

Then it should emit the attribute when you re-generate code:

[Key]
public System.Int32 OrderId { get; set;}
Attachments
Filename File size Added on Approval
customAttribute.PNG 46,113 26-May-2017 07:24.23 Approved
David Elizondo | LLBLGen Support Team
costa_b
User
Posts: 3
Joined: 25-May-2017
# Posted on: 31-May-2017 20:26:42   

daelmo wrote:

(I attached a couple of screenshots.)

Hi, thank you. I don't see the screenshots.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 01-Jun-2017 09:23:01   

Click on the paperclip icon at the top of David's post wink

Frans Bouma | Lead developer LLBLGen Pro