entity-framework-core

EFCore use a single dbconnect for the lifetime of dbcontext

我怕爱的太早我们不能终老 提交于 2019-12-12 04:32:53
问题 I'm using EFCore to steaming data to backend db, I call SaveChanges for every a certain number of new objects added to the dataset, I noticed from the EFCore debug log that it will close the connection and open a new one each time I call SaveChanges : Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerConnection|DEBUG|Opening connection to database ... Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerConnection|DEBUG|Beginning transaction with isolation level 'Unspecified'.

Error: SqlException: Invalid object name 'Clients' in Identity Server 4 Project

核能气质少年 提交于 2019-12-12 03:44:05
问题 I would like to connect Identity Server to the Sql Server in my Asp.net core AuthServer project. But I am getting the error in the InitlizeDatabase(app) step as shown in the image below. 回答1: Check the migration folder to make sure your migration is actually creating the Clients table. 回答2: It was the EF Core version issue. When I used the ef and the ef tool version as given in the documentation and it worked :) So my code works with the version below: "Microsoft.EntityFrameworkCore.Tools":

EF Core removerange items not removed on transaction

眉间皱痕 提交于 2019-12-12 03:38:50
问题 Here's my prblem using (var db = new CassaContext()) { var DbSet = db.GetByName(item.Name); DbSet.RemoveRange(DbSet); for (var i = 0; i < data.Count; i++) { JObject jitem = data[i] as JObject; var dbobj = vm.Db.JsonToObject(jitem); DbSet.Add(dbobj); } db.SaveChanges(); } If i will add db.SaveChanges() after the RemoveRange() istruction, everything is fine, but, without that, i have the error The instance of entity type 'Users' cannot be tracked because another instance of this type with the

Entity Framework 7 error : “EntityFramework.Core.resources” is missing (7.0.0-rc1-final)

核能气质少年 提交于 2019-12-12 03:32:20
问题 [SOLVED] see my answer I have a project running with ASP.NET 5 and EF7. I have my EF model in a class library, framework 4.5.1. When I try to interact with data, I have this exception : the file "EntityFramework.Core.resources" is missing. But when I put the EF model in my UI project, it works fine. Any idea what's going on ? Is it possible to have the entity framework model in a dedicated class library ? (I always did this way but maybe it has changed with this version) This is the package

Stack Overflow exception at Database.EnsureCreated EF 7 ASP.NET 5 MVC 6

别来无恙 提交于 2019-12-12 03:32:07
问题 I am encountering an error at Database creation at Application Start whereas the exact same code works perfectly fine in all other projects. Startup function in Startup.cs public Startup(IHostingEnvironment env) { // Set up configuration sources. var builder = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .AddEnvironmentVariables(); if (env.IsDevelopment()) { // This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately.

Dropdownlists not populating with data from 3 separate reference tables

主宰稳场 提交于 2019-12-12 03:26:31
问题 Currently I am working with ASP.Net MVC 6 using EF7. I am using the default controller generator. For some reason my drop downs are not populating with data on the create or edit page even though data is present. Just to clarify the 3 select lists are being populated by 3 different tables that are all connected to the main table I am adding to. Here's what I got. Controller code private readonly SchoolContext _context; public SchoolsController(SchoolContext context) { _context = context; }

Programmatically change path for EF Core database in console project

那年仲夏 提交于 2019-12-12 02:25:59
问题 I'm using EF Core, to manage a SQLite database file, in a console project. When I create a database, the file is created in the bin folder, so basically MyProjectName\bin\Debug\netcoreapp1.1\FooDatabase.sqlite . I want to change this. I tried setting Directory.SetCurrentDirectory and IHostingEnvironment.ContentRootPath . Nothing works. How do I programmatically set the directory that the database should be created in? 回答1: In Microsoft.Data.Sqlite 2.0 (not yet released), Directory

Configure more than one dbcontext in EF 7

偶尔善良 提交于 2019-12-12 01:53:33
问题 I created a web starter application with VS 2015 ctp, and I would like to add an in-memory store to do some test, but when I try to read the data, I get this message The data stores 'SqlServerDataStore' 'InMemoryDataStore' are available. A context can only be configured to use a single data store. Configure a data store by overriding OnConfiguring in your DbContext class or in the AddDbContext method when setting up services. How can I do to create a second datastore? Now I have this row in

Why won't Entity Framework Core save a new record to an SQLite table having a foreign key?

陌路散爱 提交于 2019-12-12 01:48:28
问题 I have created a following simple SQLite database for experimenting purposes: CREATE TABLE "cities" ( `id` INTEGER PRIMARY KEY AUTOINCREMENT, `name` TEXT UNIQUE ); CREATE TABLE `people` ( `id` INTEGER PRIMARY KEY AUTOINCREMENT, `city` INTEGER, `name` TEXT, `surname` TEXT, FOREIGN KEY(`city`) REFERENCES `cities`(`id`) ); Then I have used the SQLite Toolbox by @erikej to generate the model code. Right after that the following code works just fine: var context = new SqliteEfcExampleContext();

Use repository with DbContext in ASP.NET Core Authorize-Attribute: “Cannot access a disposed object”

蹲街弑〆低调 提交于 2019-12-12 01:24:44
问题 For third party authentication, I need a custom Authorize attribute. Here a repository ( SessionManager ) class is required to check if the user is logged in. [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true, Inherited = true)] public class VBAuthorizeAttribute : AuthorizeAttribute, IAuthorizationFilter { public async void OnAuthorization(AuthorizationFilterContext context) { var sessionManager = (VBSessionManager)context.HttpContext.RequestServices