entity-framework-core

Difference between “ToListAsync()” and “AsAsyncEnumerable().ToList()”

早过忘川 提交于 2021-01-03 07:10:21
问题 Function need to return Task<List<Record>> Following both options are returning Task<List<Record>> , which one is more efficient? Is there any standard way here? Option 1 : Task<List<Record>> GetRecords() { return DbContext.Set<Record>.Where(predicate).ToListAsync(); } Option 2: Task<List<Record>> GetRecords() { return DbContext.Set<Record>.Where(predicate).AsAsyncEnumerable().ToList(); } 回答1: Go for option 1 ToListAsync as the source code of AsAsyncEnumerable explicitly mentions This is an

I get an error when I add migration using Entity Framework Core

余生颓废 提交于 2021-01-01 04:27:09
问题 I built a console project and use code first to map model to database. When I run the command of Add-Migration InitialMigration , I get an error: Method 'Create' in type 'Microsoft.EntityFrameworkCore.SqlServer.Query.Internal.SqlServerSqlTranslatingExpressionVisitorFactory' from assembly 'Microsoft.EntityFrameworkCore.SqlServer, Version=3.1.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation. The DbContext is: class ActorDbContext : DbContext { public DbSet

I get an error when I add migration using Entity Framework Core

有些话、适合烂在心里 提交于 2021-01-01 04:26:26
问题 I built a console project and use code first to map model to database. When I run the command of Add-Migration InitialMigration , I get an error: Method 'Create' in type 'Microsoft.EntityFrameworkCore.SqlServer.Query.Internal.SqlServerSqlTranslatingExpressionVisitorFactory' from assembly 'Microsoft.EntityFrameworkCore.SqlServer, Version=3.1.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation. The DbContext is: class ActorDbContext : DbContext { public DbSet

Ambiguous call when using LINQ extension method on DbSet<T>

北战南征 提交于 2020-12-30 05:13:29
问题 I am using a LINQ query on a DbSet<T> : await _dbContext.Users.AnyAsync(u => u.Name == name); However, the compiler outputs the following error: Error CS0121: The call is ambiguous between the following methods or properties: 'System.Linq.AsyncEnumerable.AnyAsync<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Func<TSource, bool>)' and 'Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.AnyAsync<TSource>(System.Linq.IQueryable<TSource>, System.Linq

Ambiguous call when using LINQ extension method on DbSet<T>

被刻印的时光 ゝ 提交于 2020-12-30 05:13:27
问题 I am using a LINQ query on a DbSet<T> : await _dbContext.Users.AnyAsync(u => u.Name == name); However, the compiler outputs the following error: Error CS0121: The call is ambiguous between the following methods or properties: 'System.Linq.AsyncEnumerable.AnyAsync<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Func<TSource, bool>)' and 'Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.AnyAsync<TSource>(System.Linq.IQueryable<TSource>, System.Linq

Ambiguous call when using LINQ extension method on DbSet<T>

心不动则不痛 提交于 2020-12-30 05:12:28
问题 I am using a LINQ query on a DbSet<T> : await _dbContext.Users.AnyAsync(u => u.Name == name); However, the compiler outputs the following error: Error CS0121: The call is ambiguous between the following methods or properties: 'System.Linq.AsyncEnumerable.AnyAsync<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Func<TSource, bool>)' and 'Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.AnyAsync<TSource>(System.Linq.IQueryable<TSource>, System.Linq

Ambiguous call when using LINQ extension method on DbSet<T>

寵の児 提交于 2020-12-30 05:11:30
问题 I am using a LINQ query on a DbSet<T> : await _dbContext.Users.AnyAsync(u => u.Name == name); However, the compiler outputs the following error: Error CS0121: The call is ambiguous between the following methods or properties: 'System.Linq.AsyncEnumerable.AnyAsync<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Func<TSource, bool>)' and 'Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.AnyAsync<TSource>(System.Linq.IQueryable<TSource>, System.Linq

Ambiguous call when using LINQ extension method on DbSet<T>

a 夏天 提交于 2020-12-30 05:09:54
问题 I am using a LINQ query on a DbSet<T> : await _dbContext.Users.AnyAsync(u => u.Name == name); However, the compiler outputs the following error: Error CS0121: The call is ambiguous between the following methods or properties: 'System.Linq.AsyncEnumerable.AnyAsync<TSource>(System.Collections.Generic.IAsyncEnumerable<TSource>, System.Func<TSource, bool>)' and 'Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.AnyAsync<TSource>(System.Linq.IQueryable<TSource>, System.Linq

Drop database if model changes in EF Core without migrations

徘徊边缘 提交于 2020-12-29 06:19:24
问题 In previous version of entity framework, one could recreate the database if the model changes, using some of the classes DropDatabseIfModelChanges and other related classes. In EF7 or EF Core i don't know how to do that. Run the migrations some times give problems and in the beginning of the project i need to change the models constantly. 回答1: There's currently no easy way to implement DropDatabseIfModelChanges in EFCore. EF6 worked by storing a snapshot of your model in the _

Entity Framework Core Many to Many change navigation property names

亡梦爱人 提交于 2020-12-26 10:23:21
问题 I have a table called "LogBookSystemUsers" and I want to setup many to many functionality in EF Core 5. I almost have it working but the problem is my ID columns are named SystemUserId and LogBookId but when EF does the join it tries to use SystemUserID and LogBookID . This is my current configuration code: modelBuilder.Entity<SystemUser>() .HasMany(x => x.LogBooks) .WithMany(x => x.SystemUsers) .UsingEntity(x => { x.ToTable("LogBookSystemUsers", "LogBooks"); }); I tried this: modelBuilder