entity-framework-core

Entity Framework Core - Using Stored Procedure with output parameters

假如想象 提交于 2019-12-03 15:20:45
I'm trying to use stored procedures with new Entity Framework Core. I need to start new project soon which will be ASP.Net 5, but not sure if Entity Framework will fit for the job. The application will be triggering several stored procedures per minute and I need output parameters. Will EF be good for this or should I use ADO.Net? I have tried FromSql and database.ExecuteSqlCommand but no luck. using (AppDbContext db = factory.Create()) { var in1 = new SqlParameter { ParameterName = "ParamIn1", DbType = System.Data.DbType.Int64, Direction = System.Data.ParameterDirection.Input }; var in2 = new

Proper way to get current User ID in Entity Framework Core

懵懂的女人 提交于 2019-12-03 15:15:42
问题 There are a bunch of different answers floating around here for the different RC's of ASP.NET Core on how to get the ID of the currently logged in user. I wanted to ask the definite question here. Please note that project.json now has "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0" With RC1, you could do something like this: using Microsoft.AspNet.Identity; using System.Security.Claims; User.GetUserId(); But with the newly released version 1 of EF Core, Microsoft.AspNet.Identity

Entity Framework Core Eager Loading Then Include on a collection

左心房为你撑大大i 提交于 2019-12-03 14:45:18
问题 I have three Models that I want to include when performing a query. Here is the scenario. public class Sale { public int Id { get; set; } public List<SaleNote> SaleNotes { get; set; } } public class SaleNote { public int Id { get; set; } public User User { get; set; } } public class User { public int Id { get; set; } } I can eager load the SaleNotes like this... _dbContext.Sale.Include(s => s.SaleNotes); However, trying to eager load the User model from the SaleNote using ThenInclude is

The term “Add-Migration” is not recognized

断了今生、忘了曾经 提交于 2019-12-03 14:21:03
问题 I'm using this MSDN Tutorial to run in VS2015 the command PM> Add-Migration MyFirstMigration -context BloggingContext that ran yesterday successfully but today it's giving the following error that is also pointed out by other users here. I even deleted the Migrations folder from solution explorer and the corresponding db from SQL Express 2014 on Win 8.1 but same error. Even if I run Add-Migration MyFirstMigration I get same error: Add-Migration : The term 'Add-Migration' is not recognized as

SQLite Data Provider is missing in Visual Studio 2017

懵懂的女人 提交于 2019-12-03 14:15:05
Using Nuget Package Manager I installed System.Data.SQLite (x86/x64) in VS2017 . That resulted in installing the following packages as well: System.Data.SQLite System.Data.SQLite.EF6 System.Data.SQLite.Core But as shown in image below, the Add New Data Source dialog box does not show the SQLite Data Provider : The NuGet package is for your project and does not include a provider. For that, you need to install a DDEX provider package. There doesn't seem to be an official SQLite DDEX provider package for Visual Studio 2017, but you can try one of these two unofficial ones: SQLite / SQL Server

Entity Framework Core: Is it safe to delete Migration.Designer.cs if we will never Revert a migration?

心不动则不痛 提交于 2019-12-03 13:36:46
We have a database schema with ~200 tables. Model snapshot (Migration.Designer.cs) which is created for each migration is ~20K lines. So, having quite a number of migrations really slows down our build on CI (with ~30 migrations building a solution takes 6 minutes with migrations or 4 minutes without them). So, to the question: is it safe to delete model snapshots for old migrations (that we know we will never Revert)? Are model snapshots used for anything else except Revert-Migration? Are model snapshots used for anything else except Revert-Migration? Yes. There are a few edge cases where it

Multiple dbContexts in ASP.NET vNext and EF7

丶灬走出姿态 提交于 2019-12-03 13:36:32
问题 I'm trying to get along with building web systems with ASP.NET vNext using MVC 6 and EF7. I'm looking at this tutorial: http://stephenwalther.com/archive/2015/01/17/asp-net-5-and-angularjs-part-4-using-entity-framework-7 On the page you'll see how to add a dbContext to a project and it's registered in the startup file like this: // Register Entity Framework services.AddEntityFramework(Configuration) .AddSqlServer() .AddDbContext<MoviesAppContext>(); And the context class looks like this:

How to enable migration in SQLite using EF

喜夏-厌秋 提交于 2019-12-03 12:54:56
I have stuck in problem. I am writing a code for windows desktop application and I have to use sqlite as a database. I have successfully installed system.data.sqlite and entity framework from nuget package. I have also created my DbContext class. Now problem is that as soon as I tried to run my code an exception comes whose inner message is {"SQLite Error 1: 'no such table: TimeSheet'"}. This means your table TimeSheet does not exist in database. Plz tell me how to create table in sqlite using entity framework or how to enable migrations. bubi There are some implementations of migration for

'System.ValueTuple, Version=0.0.0.0 required for Add-Migration on .NET 4.6.1 Class Library

北城余情 提交于 2019-12-03 12:31:28
I upgraded a .net standard class library from Entity Framework Core 1.1 to Entity Framework 2.0 I am trying to run Add-Migration on an Entity Framework Core Class Library that targets .net framework 4.6.1 Add-Migration MyMigration But I then get the following error System.IO.FileLoadException: Could not load file or assembly 'System.ValueTuple, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) File name: 'System.ValueTuple, Version

How to extend DbContext with partial class and partial OnModelCreating method in EntityFramework Core

▼魔方 西西 提交于 2019-12-03 12:10:34
问题 I'm using EF Core DbFirst approach. My dbContext is created automatically by Scaffold-DbContext command. I need to add additional DbSets into a dbContext and add into OnModelCreating method of dbContext some additional code but after each scaffolding that added code are erased and I have to add it each time again. What I want to do is to create another partial dbContext class and mark protected override void OnModelCreating(ModelBuilder modelBuilder) as a partial method but get errors: A