Entity Framework 6 GUID as primary key: Cannot insert the value NULL into column ‘Id’, table ‘FileStore’; column does not allow nulls

In addition to adding these attributes to your Id column: [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid Id { get; set; } in your migration you should change your CreateTable to add the defaultValueSQL property to your column i.e.: Id = c.Guid(nullable: false, identity: true, defaultValueSql: “newsequentialid()”), This will prevent you from having to manually touch your database … Read more

Async PartialView causes “HttpServerUtility.Execute blocked…” exception

Child actions must be invoked synchronously. Issue 601 I am also not aware of any recent updates to the current MVC libraries allowing this functionality. A comment on Issue 601, hints at this functionality being added in MVC vNext, aka. MVC6. Child actions look to be replaced with ViewComponent which can be invoked asynchronously from … Read more

Multi-async in Entity Framework 6?

The exception explains clearly that there is only one asynchronous operation per context allowed at a time. So, you either have to await them one at a time as the error message suggests: var banner = await context.Banners.ToListAsync(); var newsGroup = await context.NewsGroups.ToListAsync(); Or you can use multiple contexts: var banner = context1.Banners.ToListAsync(); var newsGroup … Read more

Entity Framework 6 transaction rollback

You don’t need to call Rollback manually because you are using the using statement. DbContextTransaction.Dispose method will be called in the end of the using block. And it will automatically rollback the transaction if the transaction is not successfully committed (not called or encountered exceptions). Following is the source code of SqlInternalTransaction.Dispose method (DbContextTransaction.Dispose will … Read more

Database.BeginTransaction vs Transactions.TransactionScope [duplicate]

I found out the answer in Entity Framework 6’s documentation: With the introduction of EF6, Microsoft recommends to use new API methods: Database.BeginTransaction() and Database.UseTransaction(). Although System.Transactions.TransactionScope is still very well supported, it is no longer necessary for most users of EF6. While Database.BeginTransaction() is used only for database related operations transaction, System.Transactions.TransactionScope, in addition … Read more

How to create index in Entity Framework 6.2 with fluent configuration

Well 26.10.2017 Entity Framework 6.2 was officially released. It includes a possibility to define indexes with ease via Fluent API. Ho it is to use was already announced in the beta of 6.2. Now you can use the HasIndex() method, followed by IsUnique() if it should be an unique index. Just a small comparison (before/after) … Read more

How to update record using Entity Framework Core?

To update an entity with Entity Framework Core, this is the logical process: Create instance for DbContext class Retrieve entity by key Make changes on entity’s properties Save changes Update() method in DbContext: Begins tracking the given entity in the Modified state such that it will be updated in the database when SaveChanges() is called. … Read more

There is already an object named in the database

it seems there is a problem in migration process, run add-migration command in “Package Manager Console”: Add-Migration Initial -IgnoreChanges do some changes, and then update database from “Initial” file: Update-Database -verbose Edit: -IgnoreChanges is in EF6 but not in EF Core, here’s a workaround: https://stackoverflow.com/a/43687656/495455