Created a model (Code fluent):
public PersonConfig() { HasKey(id => id.PersonID); Property(name => name.Name).IsRequired().HasMaxLength(50); } public class Person { public int PersonID { get; set; } public string Name { get; set; } } class CodeContext: DbContext { public CodeContext(string connectionString) : base( connectionString) { } public DbSet<Person> Person{ get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Configurations.Add(new PersonConfig()); base.OnModelCreating(modelBuilder); } } After that, in the viewmodel I send the line, I do the initialization:
try { using (var cnxt = new CodeContext(connectionString)) { cnxt.Database.Initialize(true); } } catch (Exception ex) { MessageBox.Show("Произошла ошибка с сервером"); } The problem is this: if I appeal to the server, which is, then everything is fine, after working with it (if there is no database, it creates, if it does, then it uses it). But if the server string is incorrect, then the download goes about 01:07 minutes, and only after it moves to catch (exception ex). How to reduce time to the server ?? Or how to check if the server is entered correctly. Over time, I tried to write in CodeContext for 30 seconds, but it does not work .:
this.Database.CommandTimeout = 30; How to solve this problem? MB, I incorrectly do the initialization, although it doesn’t work differently, and even if the server string is correct, the call goes without problems (but the appeal to the correct server is initially about 8 seconds, which seems to be a lot, because I’m contacting myself )?