Guest User

Untitled

a guest
Feb 25th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. public class MyEntity
  2. {
  3. [Key, Column(Order=0)]
  4. public int MyFirstKeyProperty { get; set; }
  5.  
  6. [Key, Column(Order=1)]
  7. public int MySecondKeyProperty { get; set; }
  8.  
  9. [Key, Column(Order=2)]
  10. public string MyThirdKeyProperty { get; set; }
  11.  
  12. // other properties
  13. }
  14.  
  15. public class User
  16. {
  17. public int UserId { get; set; }
  18. public string Username { get; set; }
  19. }
  20.  
  21. public class Ctp5Context : DbContext
  22. {
  23. public DbSet<User> Users { get; set; }
  24.  
  25. protected override void OnModelCreating(ModelBuilder modelBuilder)
  26. {
  27. modelBuilder.Entity<User>().HasKey(u => new
  28. {
  29. u.UserId,
  30. u.Username
  31. });
  32. }
  33. }
  34.  
  35. public class User
  36. {
  37. public int UserId { get; set; }
  38. public string Username { get; set; }
  39. }
  40.  
  41. public class UserConfiguration : EntityTypeConfiguration<User>
  42. {
  43. public UserConfiguration()
  44. {
  45. ToTable("Users");
  46. HasKey(x => new {x.UserId, x.Username});
  47. }
  48. }
  49.  
  50. public class Ctp5Context : DbContext
  51. {
  52. public DbSet<User> Users { get; set; }
  53.  
  54. protected override void OnModelCreating(ModelBuilder modelBuilder)
  55. {
  56. modelBuilder.Configurations.Add(new UserConfiguration());
  57. }
  58. }
Add Comment
Please, Sign In to add comment