Excluding the default Id primary key from an Entity....
See original GitHub issueHi,
I have the following structure defined for my entities:
/// <summary>
/// Base class for all entities defined in the system. This allows for the following
/// COMMON features:
/// - Primary key "Id" of type long
/// - Auditing which adds Date & User information for creation and update
/// </summary>
public class CcaEntityCommon : AuditedEntity<long>
{
}
/// <summary>
/// Extends the common functionality by adding the ability to mark a record as deleted rather than
/// deleting it from the database. Unless there is a reason not to mark an entity as a soft delete
/// then all entities should descend from this class.
/// </summary>
public class CcaEntityBase : CcaEntityCommon, ISoftDelete
{
#region Implementation of ISoftDelete
/// <summary>
/// Used to mark an Entity as 'Deleted'.
/// </summary>
public bool IsDeleted { get; set; }
#endregion
}
And ultimately a table defined as:
[Table(“ContractorsEmployees”, Schema = “dbo”)] public class ContractorEmployeeTableModel : CcaEntityBase { #region Public Members
public ContractorTableModel Contractor { get; set; }
[Key, Column(Order = 1)]
[ForeignKey("Contractor")]
public long ContractorId { get; set; }
public EmployeeTableModel Employee { get; set; }
[Key, Column(Order = 2)]
[ForeignKey("Employee")]
public long EmployeeId { get; set; }
#endregion
}
However in this particular case the primary key is ContractorId AND EmployeeId and I don’t need the Id key. So how do I exclude it in ContractorEmployeeTableModel? Can I do it with a data annotation? Or fluent API? Or do I have to have a “different” inheritance hierachy for tables that have compound keys?
Issue Analytics
- State:
- Created 9 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
c# - Can you remove Identity from a primary key with Entity ...
Look at the ALTER TABLE - ALTER COLUMN statement: there is no syntax to change (add or remove) an identity specification. Refer flowing...
Read more >Add or change a table's primary key in Access
Access can automatically create a primary key field for you when you create a table, or you can specify the fields that you...
Read more >Documentation: 15: CREATE TABLE
Indexes, PRIMARY KEY , UNIQUE , and EXCLUDE constraints on the original table will be created on the new table. Names for the...
Read more >DAD220 Ch 3 Flashcards
No. (ID, Relationship) cannot be the primary key because (6381, Daughter) is repeated. Composite primary keys must be unique.
Read more >Define data using Room entities
By default, Room uses the class name as the database table name. ... Each Room entity must define a primary key that uniquely...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Can you map Id to your primary key? Even if their name different, you can override Id and add a [Column(“YourPkName”)] attribute to change it.
Yes did the same and its good solution. thanks. I’m wondering why I couldnt think that way 👍