I defined a DataObject as:
public class SensorType : EntityData
{
//PKs
public string CompanyId { get; set; }
public string ServiceId { get; set; }
public string Type { get; set; }
}
And used fluent API to make CompanyId and ServiceId a composite key:
modelBuilder.Entity<SensorType>()
.HasKey(t => new { t.CompanyId, t.ServiceId });
//No autogeneration of PKs
modelBuilder.Entity<SensorType>().Property(t => t.ServiceId)
.HasDatabaseGeneratedOption(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.None);
modelBuilder.Entity<SensorType>().Property(t => t.CompanyId)
.HasDatabaseGeneratedOption(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.None);
Even though a Primary Key has been set Entity Framework creates a column named Id when I run Add-Migration:
CreateTable(
"dbo.SensorTypes",
c => new
{
CompanyId = c.String(nullable: false, maxLength: 128),
ServiceId = c.String(nullable: false, maxLength: 128),
Type = c.String(),
Id = c.String(
annotations: new Dictionary<string, AnnotationValues>
{
{
"ServiceTableColumn",
new AnnotationValues(oldValue: null, newValue: "Id")
...
})
.PrimaryKey(t => new { t.CompanyId, t.ServiceId })
.Index(t => t.CreatedAt, clustered: true);
}
How do I prevent EF from adding this column?