ApplicationDbContext.cs 986 B

1234567891011121314151617181920212223242526272829303132
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.Entity;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using ConsoleHttp.Model;
  8. using MqttMsgServer.Model;
  9. namespace MqttMsgServer.Dao
  10. {
  11. public class ApplicationDbContext:DbContext
  12. {
  13. public ApplicationDbContext():base(AppSetting.GetValue("SqlServerConnectionString"))
  14. {
  15. // Database.SetInitializer(new DropCreateDatabaseIfModelChanges<ApplicationDbContext>());
  16. }
  17. public IDbSet<ClientInfos> ClientInfos { get; set; }
  18. public IDbSet<ReceiveMessageRecord> ReceiveMessageRecords { get; set; }
  19. protected override void OnModelCreating(DbModelBuilder modelBuilder)
  20. {
  21. base.OnModelCreating(modelBuilder);
  22. modelBuilder.Entity<ClientInfos>().Property(i=>i.Id).HasMaxLength(50);
  23. modelBuilder.Entity<ReceiveMessageRecord>().Property(i=>i.Id).HasMaxLength(50);
  24. }
  25. }
  26. }