Hi,
Is there anything in the framework that might get in the way of overriding the default name and type for an entities PK please?
Marking a property like this results in the right primary key being defined:
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid SupplierId { get; set; }
However, the EF default of "Id" is still created. Naming a property "<EntityClassName>Id" should suppress this:
[attachment=0:ji9x8gu7]Capture.JPG[/attachment:ji9x8gu7] Thanks for any guidance.
Cheers,
2 Answer(s)
-
0
Hi,
You can derive your entity from Entity<TKey> and override Id as shown below:
public class Supplier : Entity<Guid> { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public override Guid Id { get; set; } //...your other properties }
Entity's primary key must be Id in ABP framework. If you want to map it to a different field in db, you can add a [Column("SupplierId")] to the Id property. But the entity model's id should be Id.
-
0
Thanks hikalkan.
For those who are interested, to override Id with guid datatype and also implement the full audit log pattern, do this:
[Table("Supplier")] public class Supplier : **FullAuditedEntity<Guid>** { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public override Guid Id { get; set; }