Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyEntity
- {
- [Key, Column(Order=0)]
- public int MyFirstKeyProperty { get; set; }
- [Key, Column(Order=1)]
- public int MySecondKeyProperty { get; set; }
- [Key, Column(Order=2)]
- public string MyThirdKeyProperty { get; set; }
- // other properties
- }
- public class User
- {
- public int UserId { get; set; }
- public string Username { get; set; }
- }
- public class Ctp5Context : DbContext
- {
- public DbSet<User> Users { get; set; }
- protected override void OnModelCreating(ModelBuilder modelBuilder)
- {
- modelBuilder.Entity<User>().HasKey(u => new
- {
- u.UserId,
- u.Username
- });
- }
- }
- public class User
- {
- public int UserId { get; set; }
- public string Username { get; set; }
- }
- public class UserConfiguration : EntityTypeConfiguration<User>
- {
- public UserConfiguration()
- {
- ToTable("Users");
- HasKey(x => new {x.UserId, x.Username});
- }
- }
- public class Ctp5Context : DbContext
- {
- public DbSet<User> Users { get; set; }
- protected override void OnModelCreating(ModelBuilder modelBuilder)
- {
- modelBuilder.Configurations.Add(new UserConfiguration());
- }
- }
Add Comment
Please, Sign In to add comment