You can easily do this as follows using the Fluent API:
modelBuilder.Entity<YourClass>().HasKey(obj => new {obj.Id,obj.Nr});
In addition, you can create a separate class that inherits from EntityTypeConfigurationand add this line to your constructor:
public class <*Name*>Mapping:EntityTypeConfiguration<*Name*>
public <*Name*>Mapping(){
this.HasKey(obj => new {obj.Id,obj.Nr});
}
}
source
share