entity-framework-core

How does EF7 bootstrap dependency injection (IServiceCollection) if you're not in ASP.NET 5?

坚强是说给别人听的谎言 提交于 2019-12-03 21:26:29
I'm still trying to get my head around what's what with ASP.NET 5 / EF 7. I'm using DNX projects (.xproj). Startup is used by OWIN/ASP.NET for configuring, loading services, etc. But it's also used for EF 7 migrations (to set your DbContextOptions for example). My main goal is to know how EF7 (and ASP.NET 5) bootstrap with Startup and who's creating the startup class, initializing the DI container, etc. An example of what I need to do, for context, is that in my xUnit unit tests (which are in their own assembly and reference my data assembly which doesn't have a Startup class), I need to

The current runtime target framework is not compatible with project

爱⌒轻易说出口 提交于 2019-12-03 19:50:05
问题 I am attempting to perform an initial migration after adding Entity Framework 7 to my Asp.Net 5 project. I am following this documentation. In my project.json I have specified: "commands": { "web": "Microsoft.AspNet.Server.Kestrel", "ef": "EntityFramework.Commands" }, "frameworks": { "dnxcore50": { } } I am attempting to execute the following command in the project directory via a command prompt: dnx ef migrations add MyFirstMigration But I get the following error: System

EF Core Error - No project was found. Change the current working directory or use the --project option

允我心安 提交于 2019-12-03 19:11:16
问题 I am using Visual Studio 2015 and dotnet core and trying to develop an EF Core Code First project using Sqlite and this documentation / tutorial, which also uses Sqlite => NET Core - New Database When I try to add an initial migration from the command line ( I am CD-ed into the folder that my data model project is located in) by issuing the following command dotnet ef migrations add InitialMigration ...I get the following Error. No project was found. Change the current working directory or

DotNet Core setting the connection string after startup has run

时光毁灭记忆、已成空白 提交于 2019-12-03 18:11:33
问题 I have a Visual Studio solution that has two database connections. The first is a catalog holding username password and database. The second will be the users data. I can set up the connection for the catalog database in "ConfigureServices" and thats fine. Once the user has attempted to log in and succeeded I can then know the database the user will connect to. My problem is, How do I create the service after startup has run.. how do I use the connection string to add a DBcontext in the

Why Linq “where” expression after Select gets evaluated locally when created through a generic method?

六眼飞鱼酱① 提交于 2019-12-03 16:24:00
I'm implementing Specification pattern with generics and trying to dynamically apply criteria to projected simple (unmapped) versions of mapped entities. In general, it works fine, but Linq evaluates the expression locally as soon as I add Select and apply Where after it. The exact same Linq expression yields correct SQL query, if I build it as a local variable and pass to the same Where . Here's the simplified relevant code snippet: public interface ISomeable { string Some { get; set; } } public static Expression<Func<T, bool>> GetCriteria<T>() where T : class, ISomeable { return e => (e.Some

EF 7 Migration to Existing Database

别说谁变了你拦得住时间么 提交于 2019-12-03 16:11:29
I am working on a web project using ASP.Net 5 and EF7. I have imported all the tables from existing database onto my models in my project. However, I am having problems in regards with migrations. I have created the initial migration, made some changes on particular entity, create another migration following the changes I have made and now want to apply the changes on the database. After running this command below: dnx ef database update [Migration] the dnx is trying to apply the 'initial' migration with all the entities which are already in database and this causes an error as below: { There

Azure Function, EF Core, Can't load ComponentModel.Annotations 4.2.0.0

假装没事ソ 提交于 2019-12-03 16:07:30
问题 I have created several .Net Standard 2.0 libraries, tested the execution via a console application, as well as several tests - all is good. Move over to azure function, and get the following run-time error: I then try to download that specific version into the API Function project: I'm using Visual Studio Version 15.7.0 Preview 5.0. I have updated the Azure Function to 4.7... as the console and test projects are - and those work. Been at this a far too many hours.. so I'm hoping the

Where are Entity Framework Core conventions?

六眼飞鱼酱① 提交于 2019-12-03 15:41:43
问题 using EF 6.1+ there were times where we need to add or remove existing conentions. The code looks more or less like: public class MyContext : DbContext { protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Conventions.AddFromAssembly(Assembly.GetExecutingAssembly()); modelBuilder.Conventions.Remove<PluralizingTableNameConvention>(); modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>(); modelBuilder.Conventions.Remove

Case insensitive name of tables and properties in Entity Framework 7

让人想犯罪 __ 提交于 2019-12-03 15:35:25
I use Entity Framework 7 with Npgsql adapter. Sql generated by EF seems like SELECT "r"."Id", "r"."Name" FROM "public"."Role" AS "r" and it doesn't work in Postgres, because case-sensitive policy. To make it work i need to write create table script CREATE TABLE "Role" ( "Id" int, "Name" varchar(200) ); But it's ugly. Is there the way to make EF generate scripts without quotes or with lowercase naming style? Shay Rojansky There's a very good reason Npgsql generates quotes everywhere - so you definitely should not remove them (even if it's technically possible as @natemcmaster says). Identifiers

How to allow migration for a console application?

时光总嘲笑我的痴心妄想 提交于 2019-12-03 15:32:33
When using asp.net core and ef core, I have no problem when invoking add-migration init . But when I apply the same approach on a console application below, I got an error saying: Unable to create an object of type 'StudentContext'. Add an implementation of 'IDesignTimeDbContextFactory' to the project, or see https://go.microsoft.com/fwlink/?linkid=851728 for additional patterns supported at design time. What is the easiest way to fix this issue? The .net core console application project is as follows: appsettings.json { "ConnectionStrings": { "Storage": "Data Source=storage.db" } } EFCore