Scaffold-DbContext (EF Core Tools) throws ‘Instance failure’ exception

I think you need to change your instance name. For example : Scaffold-DbContext “Server=PC\SQLEXPRESS;Database=***;User ID=sa;Password=****” Microsoft.EntityFrameworkCore.SqlServer -OutputDir model So your instance in this case is : PC\\SQLEXPRESS. This instance should be like this : .\SQLEXPRESS

Seed entity with owned property

Currently this information is missing from the documentation (tracked by #710: Document how to seed owned types). It’s explained by EF Core team (with example) in the #12004: Problem seeding data that contains owned type thread: Owned types must be seeded with a HasData call after the OwnsOne call. Also, since owned types by convention … Read more

How to validate uploaded file in ASP.Net Core

You could custom validation attribute MaxFileSizeAttribute like below MaxFileSizeAttribute public class MaxFileSizeAttribute : ValidationAttribute { private readonly int _maxFileSize; public MaxFileSizeAttribute(int maxFileSize) { _maxFileSize = maxFileSize; } protected override ValidationResult IsValid( object value, ValidationContext validationContext) { var file = value as IFormFile; if (file != null) { if (file.Length > _maxFileSize) { return new ValidationResult(GetErrorMessage()); … Read more

Change the IDENTITY property of a column, the column needs to be dropped and recreated

I ran into the same problem, and I solved it by two steps and two migrations: Step 1 Drop the identity column. Comment the ID in BankAccount and add a new one (i.e., BankAccountId as identity, add migration and update – this drops id). Add a new column as identity. Step 2 Drop the newly … Read more

Setting the default value of a DateTime Property to DateTime.Now inside the System.ComponentModel Default Value Attrbute

You cannot do this with an attribute because they are just meta information generated at compile time. Just add code to the constructor to initialize the date if required, create a trigger and handle missing values in the database, or implement the getter in a way that it returns DateTime.Now if the backing field is … Read more