The provider for the source IQueryable doesn’t implement IAsyncQueryProvider

I get stuck on this issue today and this lib resolve it for me https://github.com/romantitov/MockQueryable completely, please refer: Mocking Entity Framework Core operations such ToListAsync, FirstOrDefaultAsync etc. //1 – create a List<T> with test items var users = new List<UserEntity>() { new UserEntity{LastName = “ExistLastName”, DateOfBirth = DateTime.Parse(“01/20/2012”)}, … }; //2 – build mock by … Read more

Configure multiple database Entity Framework 6

It’s not important that how many DbContexts you have(In entity framework 6). Just put connection strings in appConfig or webConfig of startup project. Then you’re ready to go. Example of appConfig with two connectionString with Ef 6.01 & Sql Compact 4.0 <configSections> <section name=”entityFramework” type=”System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″ requirePermission=”false” /> </configSections> <connectionStrings> <add name=”MainDb” … Read more

Application can’t scaffold items

In my case I moved my connection strings out of the Web.config to <connectionStrings configSource=”ConnectionStrings.config”/> that when I started getting the error when I was trying to scaffold. There was an error running the selected code generator: ‘Exception has been thrown by the target of an invocation.’ Moving my connection strings back to the Web.config … 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

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

Problems using Entity Framework 6 and SQLite

Just thought I’d share another way to configure EF6 with SQLite without using app.config / web.config. EF6 now supports code based configurations as outlined here on msdn. I used the following code (updated to remove reflection thanks to Sly): public class SQLiteConfiguration : DbConfiguration { public SQLiteConfiguration() { SetProviderFactory(“System.Data.SQLite”, SQLiteFactory.Instance); SetProviderFactory(“System.Data.SQLite.EF6”, SQLiteProviderFactory.Instance); SetProviderServices(“System.Data.SQLite”, (DbProviderServices)SQLiteProviderFactory.Instance.GetService(typeof(DbProviderServices))); } … Read more