entity-framework-core

AsNoTracking on context properties, query or ChangeTracker?

社会主义新天地 提交于 2019-12-10 03:56:32
问题 I noticed that it is possible to disable tracking in three different ways: via AsNoTracking on context properties via AsNoTracking on the final query before executing it via context.ChangeTracker.QueryTrackingBehavior Is there any difference between these three approaches if I want to disable tracking for everything? If I previously used AsNoTracking after each context property and now I replace it with only a single call on the final query (or disable it via the ChangeTracker ) will it have

Unable to use data annotations

耗尽温柔 提交于 2019-12-10 03:14:30
问题 So here we are trying to get a handle on EF7 ahead of the game and I'm running into what I can only call madness. In EF6 I use annotations quite a bit and I am trying to carry that over into EF7 which according to the UnicornStore project this is totally valid, however I'm running into a problem wherein visual studio 2015 complains that I don't have a reference to the System.ComponentModel.DataAnnotations assembly. Fair enough, I add my reference to the assembly and now I get the following

Entity Framework Core - change schema of “__EFMigrationsHistory” table

∥☆過路亽.° 提交于 2019-12-10 02:39:55
问题 Is it possible to change schema of __EFMigrationsHistory table in EntityFramework Core? 回答1: Do it in your call to UseSqlServer . optionsBuilder .UseSqlServer( "...", x => x.MigrationsHistoryTable( HistoryRepository.DefaultTableName, "mySchema")); 回答2: Looking into source code (HistoryRepository.cs). You can configure custom migrations table and schema names, inside DbContext constructor public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { var

Entity Framework Core 1.0 Connection Strings

帅比萌擦擦* 提交于 2019-12-10 01:21:47
问题 We are working on a vary large ASP.NET Core MVC 1.0 application. We have 4-tiers to each of our applications as follows: DTO Repository (Entity Framework - Code First) Service (Business Logic) MVC (UI-MVC) Currently, in our repositories, which handle all database operations we have hard coded the database connection strings in the DbContext as follows: protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer("Data Source=somedatabase.database

Entity Framework 7 DbContext scaffold

送分小仙女□ 提交于 2019-12-10 01:17:37
问题 I am trying to generate a DbContext for an existing database structure using ASP.NET 5 and Entity Framework 7. Not surprisingly, there isn't a lot of documentation surrounding how to do this easily. Additionally, I want to scaffold ONLY the context; there are ~900 tables and I only care about a few of them, I don't need a model class for each one. I've been using the commands specified here and here with little luck. So, I guess I have two questions: Where are the generated context files

Unable to edit db entries using EFCore, EntityState.Modified: “Database operation expected to affect 1 row(s) but actually affected 0 row(s).”

北城余情 提交于 2019-12-10 01:06:34
问题 I'm using Identity Core 1.0 with ASP.NET MVC Core 1.0 and Entity Framework Core 1.0 to create a simple user registration system with this article as a starting point, and I am trying to add user roles. I can add user roles, but I'm unable to edit them. Here is the Edit action in the RolesController : [HttpPost] [ValidateAntiForgeryToken] public IActionResult Edit(IdentityRole role) { try { _db.Roles.Attach(role); _db.Entry(role).State = Microsoft.EntityFrameworkCore.EntityState.Modified; _db

Execute SQL command in Entity Framework Core 2.0 to delete all data in a table

前提是你 提交于 2019-12-10 00:50:25
问题 I want to execute an SQL command from Entity Framework Core 2.0, but I can't figure out how to do so. 1.- The reason why I need to, is that I want to delete all data from a database table, and using Context.remove or Context.removeRange would produce many calls to DB (one for each data in the table). 2.- I've read that there is a method .ExecuteSqlCommand to accomplish that, but that method is not present in my Context.Database (maybe in Core 2.0 it was removed?). Here is the source of the

How to call stored procedure with table valued parameter from .net core Entity Framework

孤人 提交于 2019-12-09 19:30:37
问题 I have a stored procedure with table valued parameter. I have to call it from Entity framework in .net core. I couldn't find any API on context object. I have tried with ADO.net API's and it worked but now I have to call it from EF in .net core. Stored procedure which I have to call returning result which I have to catch. My sample SP as below CREATE PROCEDURE [dbo].[GetMyData] @MyRequest [dbo].[MyRequestType] Readonly As BEGIN --Its sample SP thats why returned request table as it is select

Entity Framework Core Migration for ASP.Net Core Class Library

北慕城南 提交于 2019-12-09 18:37:42
问题 I've been trying to follow the advice of Ben Cull (http://benjii.me/2016/06/entity-framework-core-migrations-for-class-library-projects), but the database is a little different in that I'm trying to inherit from ASP.NET Core IdentityUser class. I created a new solution containing the default ASP.NET Core Web Application from the VS2015 template (CodeFirstTest). I then added an ASP.NET Core class-library (CodeFirstTest.User) to the solution, which would be the data layer in the application and

Entity Framework 7 no database provider is configured => when migrations are moved to another project

拜拜、爱过 提交于 2019-12-09 15:39:44
问题 I am new to EF7. I know this is a duplicate question to: No database providers are configured EF7 But wait before you want to have this question closed... and read on services.AddEntityFramework() .AddSqlServer() .AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"])); services.AddIdentity<ApplicationUser, IdentityRole>() .AddEntityFrameworkStores<ApplicationDbContext>() .AddDefaultTokenProviders(); services.AddScoped