Check if there are any pending changes to be saved
Starting with EF 6, there is context.ChangeTracker.HasChanges().
Starting with EF 6, there is context.ChangeTracker.HasChanges().
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
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
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
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
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
I think it is good to categorize relations like this When to use eager loading In “one side” of one-to-many relations that you sure are used every where with main entity. like User property of an Article. Category property of a Product. Generally When relations are not too much and eager loading will be good … Read more
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
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
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