How can I stop EF Core from creating a filtered index on a nullable column

Creating filtered index excluding NULL values is the default EF Core behavior for unique indexes containing nullable columns. You can use HasFilter fluent API to change the filter condition or turn it off by passing null as sql argument: entityBuilder.HasIndex(e => new { e.LevelId, e.Name, e.DeletedAt }) .IsUnique() .HasFilter(null);

AutoFac / .NET Core – Register DBcontext

I use Autofac to register both HttpContextAccessor and DbContext. builder .RegisterType<HttpContextAccessor>() .As<IHttpContextAccessor>() .SingleInstance(); builder .RegisterType<AppDbContext>() .WithParameter(“options”, DbContextOptionsFactory.Get()) .InstancePerLifetimeScope(); DbContextOptionsFactory public class DbContextOptionsFactory { public static DbContextOptions<AppDbContext> Get() { var configuration = AppConfigurations.Get( WebContentDirectoryFinder.CalculateContentRootFolder()); var builder = new DbContextOptionsBuilder<AppDbContext>(); DbContextConfigurer.Configure( builder, configuration.GetConnectionString( AppConsts.ConnectionStringName)); return builder.Options; } } DbContextConfigurer public class DbContextConfigurer { public static void Configure( … Read more

FirstOrDefaultAsync() & SingleOrDefaultAsync() vs FindAsync() EFCore

FindAsync In much of the scaffolded code, FindAsync can be used in place of FirstOrDefaultAsync. SingleOrDefaultAsync fetches more data and does unnecessary work. throws an exception if there’s more than one entity that fits the filter part. FirstOrDefaultAsync doesn’t throw if there’s more than one entity that fits the filter part. https://learn.microsoft.com/en-us/aspnet/core/data/ef-rp/crud?view=aspnetcore-2.2#singleordefaultasync-vs-firstordefaultasync

Cascade deleting with EF Core

Cascade delete always works in one direction – from principal entity to dependent entity, i.e. deleting the principal entity deletes the dependent entities. And for one-to- many relationships the one side is always the principal and the many side is the dependent. Looks like you are confused by the fluent configuration. Note that each relationship … Read more