I defined the DataObject as:
public class SensorType : EntityData
{
public string CompanyId { get; set; }
public string ServiceId { get; set; }
public string Type { get; set; }
}
And used the free API to make CompanyId and ServiceId composite:
modelBuilder.Entity<SensorType>()
.HasKey(t => new { t.CompanyId, t.ServiceId });
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);
Although the primary key is installed, the Entity Framework creates a column called Id when Add-Migration starts:
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 to prevent EF from adding this column?
source
share