entity-framework-core

Converting EF Core queries from 2.2 to 3.0 - async await

坚强是说给别人听的谎言 提交于 2020-04-07 03:58:16
问题 In EF Core 2.2 I had: var data = await _ArticleTranslationRepository.DbSet .Include(arttrans => arttrans.Article) .ThenInclude(art => art.Category) .Where(trans => trans.Article != null && trans.Article.Category != null && trans.Article.Category.Id == categoryId.Value) .GroupBy(trans => trans.ArticleId) .Select(g => new { ArticleId = g.Key, TransInPreferredLang = g.OrderByDescending(trans => trans.LanguageId == lang).ThenByDescending(trans => trans.LanguageId == defaultSiteLanguage).ThenBy

Protect an SQLite database in an UWP app

半城伤御伤魂 提交于 2020-03-26 07:19:39
问题 It is an UWP application using a SQLite database. Below, the dependencies for this application: { "dependencies": { "Microsoft.EntityFrameworkCore.Sqlite": "1.0.1", "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final", "Microsoft.NETCore.UniversalWindowsPlatform": "5.2.2", "Microsoft.Xaml.Behaviors.Uwp.Managed": "1.1.0", "Newtonsoft.Json": "8.0.3", "Template10": "1.1.*" }, // ... } The requirement is: " [...]to have a password to access the database either from the application or any

“A second operation started on this context” EF core 3.1 concurrency breaking change [duplicate]

廉价感情. 提交于 2020-03-25 16:20:13
问题 This question already has answers here : Entity Framework Core thread safe? (1 answer) Is DbContext thread safe? (3 answers) Entity Framework Thread Safety (3 answers) Closed 18 days ago . I'm migrating from netcoreapp 2.1 to 3.1, and I've found a breaking change for EF core 3.1 that I can't resolve. Previously in 2.1, this worked: taskList.Add(MethodOne(myRequestObject)); taskList.Add(MethodTwo(myRequestObject)); await Task.WhenAll(taskList); where both methods only read(never changed) from

“A second operation started on this context” EF core 3.1 concurrency breaking change [duplicate]

这一生的挚爱 提交于 2020-03-25 16:17:23
问题 This question already has answers here : Entity Framework Core thread safe? (1 answer) Is DbContext thread safe? (3 answers) Entity Framework Thread Safety (3 answers) Closed 18 days ago . I'm migrating from netcoreapp 2.1 to 3.1, and I've found a breaking change for EF core 3.1 that I can't resolve. Previously in 2.1, this worked: taskList.Add(MethodOne(myRequestObject)); taskList.Add(MethodTwo(myRequestObject)); await Task.WhenAll(taskList); where both methods only read(never changed) from

EF Core 3: Configure backing field of navigation property

不羁的心 提交于 2020-03-23 09:56:15
问题 Consider the following class. It tries to protect the access to the _assignedTrays . Actually, it works perfectly, since EF automatically links the backing field _assignedTrays to the property AssignedTrays - by convention (msdn) public class Rack { private List<Tray> _assignedTrays = new List<Tray>(); private Rack() { } public Rack(string rackId) { this.Id = rackId; } public string Id { get; private set; } public IReadOnlyList<Tray> AssignedTrays => this._assignedTrays.AsReadOnly(); public

EF Core 3: Configure backing field of navigation property

*爱你&永不变心* 提交于 2020-03-23 09:56:10
问题 Consider the following class. It tries to protect the access to the _assignedTrays . Actually, it works perfectly, since EF automatically links the backing field _assignedTrays to the property AssignedTrays - by convention (msdn) public class Rack { private List<Tray> _assignedTrays = new List<Tray>(); private Rack() { } public Rack(string rackId) { this.Id = rackId; } public string Id { get; private set; } public IReadOnlyList<Tray> AssignedTrays => this._assignedTrays.AsReadOnly(); public

Unable to run commands. Error: No database provider has been configured for this DbContext

我只是一个虾纸丫 提交于 2020-03-22 09:05:08
问题 I am unable to run EntityFramework Core commands against the basic .NET Core 2.2 Web API I created. The API is working, but I can not 'add-migration' or 'update-database' unless I change where the connection string is retrieved. I believe the first example is best practice because the connection string is more secure, but I get an error when trying to run EF Core commands. "No database provider has been configured for this DbContext. A provider can be configured by overriding the DbContext

SQLite scaffolding with Entity Framework Core

十年热恋 提交于 2020-03-21 19:26:15
问题 When I run Scaffold-DbContext "Filename=mydatabase.sqlite3" Microsoft.EntityFrameworkCore.Sqlite I get an empty context using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata; namespace MyNamespace { public partial class mydatabaseContext : DbContext { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlite(@"Filename=mydatabse.sqlite3"); } protected override void OnModelCreating(ModelBuilder modelBuilder) { } } } Am

SQLite scaffolding with Entity Framework Core

倾然丶 夕夏残阳落幕 提交于 2020-03-21 19:25:28
问题 When I run Scaffold-DbContext "Filename=mydatabase.sqlite3" Microsoft.EntityFrameworkCore.Sqlite I get an empty context using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata; namespace MyNamespace { public partial class mydatabaseContext : DbContext { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlite(@"Filename=mydatabse.sqlite3"); } protected override void OnModelCreating(ModelBuilder modelBuilder) { } } } Am

How to enable logging in EF Core 3?

断了今生、忘了曾经 提交于 2020-03-20 06:35:28
问题 I am using Entity Framework Core 3 Preview 5 and ASP.NET Core 3 Preview 5. In my Debug Output Window of Visual Studio 2019 I get no logs from EF Core. I read the documentation, but after that I am even more confused: According to https://docs.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.dbcontextoptionsbuilder.useloggerfactory?view=efcore-2.1 logging should be setup automatically: There is no need to call this method when using one of the 'AddDbContext' methods. 'AddDbContext'