entity-framework-core

Skip and Take in Entity Framework Core

落爺英雄遲暮 提交于 2019-12-12 12:08:31
问题 I have simple POCO classes: public class Library { [Key] public string LibraryId { get; set; } public string Name { get; set; } public List<Book> Books { get; set; } } public class Book { [Key] public string BookId { get; set; } public string Name { get; set; } public string Text { get; set; } } And I have query, that returns libraries with already included books: dbContext.Set<Library>.Include(x => x.Books); I'm trying to skip 5 libraries and then take 10 of them: await dbContext.Set<Library

EF Core Migration error: “Unable to create an object of type 'ApplicationContext'”

橙三吉。 提交于 2019-12-12 11:26:26
问题 I'm trying to do the migration with EF Core but I get an error - how can I fix this error? PM> add-migration ini Unable to create an object of type 'ApplicationContext'. Add an implementation of 'IDesignTimeDbContextFactory' to the project, or see https://go.microsoft.com/fwlink/?linkid=851728 for additional patterns supported at design time. 回答1: This will also happen if you have multiple start-up projects - when migrating, just select one (in VS right click Solution and Set StartUp Projects

.Net Core 2.0 with EF7 connecting to SQL Server Express. Error: 26 - Error Locating Server/Instance

二次信任 提交于 2019-12-12 11:22:59
问题 I am trying to connect to an 2008R2 SQLEXPRESS instance that is running on a 2003 server. I can connect to the database from within my .net core 2.0 project using Server Explorer I can run programs written in .net framework that connect to the database. However when I try to connect from within my .net core project I get the following error System.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The

How do I debug an Android app that crashes only in Release Mode

落爺英雄遲暮 提交于 2019-12-12 10:53:54
问题 Everything works in Debug Mode but Crashes in Release Mode. What required permissions are available in Debug Mode that are not turned on in Release mode? EDIT When I set Linking to None, I get past the first screen to my Login screen. However, when I added the Release permission Internet , the first time it tries to read a remote Entity Framework Core Table it crashes. EDIT 2 In Release Mode, if I check Use Shared Runtime , the app runs fine. EDIT 3 I have turned on Debugging while in Release

Could not load assembly Microsoft.EntityFrameworkCore.Design when running Add-Migration

耗尽温柔 提交于 2019-12-12 09:42:54
问题 I have created a Class Library project with the following .csproj: <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netcoreapp1.1</TargetFramework> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.1" /> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.1" /> <PackageReference Include="Microsoft.EntityFrameworkCore.sqlserver.Design" Version="1.1.1" /> <PackageReference Include="Microsoft

how to add config file in Class Library, followed by connection string for .NET Core 1.1

徘徊边缘 提交于 2019-12-12 09:41:02
问题 I am working on n-tier application, where I have Data Access Layer. which is independent to any other application. I have create Class Library for .NET Core 1.1, I can see dependencies folder but not any config/JSON file. I want to know, Can I add AppSetting.JSON file in class library project? followed by how can I add connection string. I am aware to override ConfigureBuilder in DbContext class --> SQLServerConnection but I want to keep in separate config file and refer to these connection

How to set Entity Framework Core migration timeout?

依然范特西╮ 提交于 2019-12-12 09:33:41
问题 I'm using the latest (1.0.0) version of EF Core. I have a migration to run on a quite big database. I run: dotnet ef database update -c ApplicationDbContext And get: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. In the connection string I explicitly set the timeout like so: Connect Timeout=150000 Unfortunately, it didn't help. How should I do this? 回答1: The error message you are getting is for a Command timeout, not a

EF Core / DbContext > Map custom type as primary key

送分小仙女□ 提交于 2019-12-12 08:53:45
问题 Using the fluent api, how do I map a custom type as the primary key within my OnModelCreating method of the DbContext class? Using EF Core I'm trying to build a model for the follow entity. public class Account { public AccountId AccountId { get; } public string Name { get; set; } private Account() { } public Account(AccountId accountId, string name) { AccountId = accountId; Name = name; } } Where the primary key is the AccountId ; the type is a simple value object like this. public class

No database provider has been configured for this DbContext

好久不见. 提交于 2019-12-12 08:48:01
问题 I recently updated my project to the latest version of Entity Framework Core (+VS2017). When I try to update the DB I get the following error message. The error message is clear, but it appears to be wrong. I do have a AddDbContext in my ConfigureServices (see code below). What am I missing? Error > dotnet ef database update --verbose Finding DbContext classes... Using context 'ApplicationDbContext'. System.InvalidOperationException: No database provider has been configured for this DbContext

Entity Framework core configurations

房东的猫 提交于 2019-12-12 08:37:04
问题 In EF 6 we could directly pass EntityTypeConfiguration to model builder to build maps and keep our configuration class separate from context without being too verbose in code. Have they removed those maps in EF core. Is there a way to add configuration without doing it in model builder for every class? 回答1: The best way is to keep the configuration code away from the OnModelCreating method. So you can do something like: Create a class where you will store the actual configuration: public