{
public int Id { get; set; }
public int Age { get; set; }
public string Name { get; set; }
public string Status { get; set; }
}
context.Users.Where(x=>x.Name == name && x.Age == age).FirstOrDefault(x => x.Status == status);
public class User
{
[Key]
public int Id { get; set; }
public int Age { get; set; }
[MaxLength(60)]
public string Name { get; set; }
[MaxLength(20)]
public string Status { get; set; }
public override string ToString() => $"id: {Id} Name: {Name} Age: {Age} Status: {Status}";
}
public class UserContext : DbContext
{
public static readonly ILoggerFactory LoggerFactory
= new LoggerFactory(new[] {
new ConsoleLoggerProvider((category, level) =>
category == DbLoggerCategory.Database.Command.Name &&
level == LogLevel.Information, true)
});
public UserContext() : base()
{
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder
.UseLoggerFactory(LoggerFactory) // для отключения логгирования закоменнтировать строку
.EnableSensitiveDataLogging() // для отключения логгирования закоменнтировать строку
.UseSqlServer(@"Server=.;Database=UserTestDB;Trusted_Connection=True;");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<User>()
.HasIndex(b => b.Status)
.HasName("IX_Status");
modelBuilder.Entity<User>()
.HasIndex(b => b.Age)
.HasName("IX_Age");
modelBuilder.Entity<User>()
.HasIndex(b => b.Name)
.HasName("IX_Name");
}
public DbSet<User> Users { get; set; }
}