entity-framework-core

Paging with Entity Framework 7 and SQL Server 2008

你说的曾经没有我的故事 提交于 2019-12-17 17:56:08
问题 I'm trying to use paging (that is .Skip(...).Take(...) in Entity Framework 7. It works OK with Microsoft SQL Server 2012 and 2014, but fails with the following error on SQL Server 2008: System.Data.SqlClient.SqlException (0x80131904): Incorrect syntax near 'OFFSET'. Invalid usage of the option NEXT in the FETCH statement. I've figured out that it is a breaking change in EF version 6.1.2 (http://erikej.blogspot.com/2014/12/a-breaking-change-in-entity-framework.html). But the fix is to modify

How can I stop EF Core from creating a filtered index on a nullable column

荒凉一梦 提交于 2019-12-17 16:44:30
问题 I have this model: public class Subject { public int Id { get; set; } [Required] [StringLength(50)] public string Name { get; set; } public int LevelId { get; set; } [ForeignKey("LevelId")] public Level Level { get; set; } [Column(TypeName = "datetime2")] public DateTime? DeletedAt { get; set; } } And index configured via Fluent API: entityBuilder.HasIndex(e => new { e.LevelId, e.Name, e.DeletedAt }) .IsUnique(); It's creating a table with a unique filtered index. How can I prevent EF from

Using EF Core ThenInclude() on Junction tables

风流意气都作罢 提交于 2019-12-17 16:27:11
问题 I'm transfering my .NET Framework (EF6) code to ASP.NET Core (EF Core), and I stumbled upon this issue. Here is some example code: In EF6 I use Include() and Select() for eager-loading: return _context.Post .Include(p => p.PostAuthor.Select(pa => pa.Author).Select(a => a.Interests)) PostAuthor is a junction table and there is also a Junction table "AuthorInterest" which I didn't need to involve in EF6 (Select goes straight to a.Interests). Anyway, I can see that in EF7 this is reworked,

Showing classes from indirectly referenced packages in .NET Core

有些话、适合烂在心里 提交于 2019-12-17 16:07:03
问题 I am trying to implement basic UoW/Repository pattern with ASP.NET/Entity Framework Core and I have encountered very troubling behavior. My solution consists of 4 projects in total. .DAL project , where my entity classes are defined and where my DbContext is defined: public class Product { public int Id { get; set; } public string Name { get; set; } } public class ApplicationDbContext : DbContext { public DbSet<Product> Products { get; set; } } .Facade project, where my IUnitOfWork and

MVC 6 EF7 RC1 creating multiple dbcontexts

試著忘記壹切 提交于 2019-12-17 12:37:41
问题 I am trying to figure out how to create a second DB context in EF7 RC1. In the past I could use a constructor with :base("connectionName") but that no longer seems an option since it says cannot convert string to System.IServiceProvider. My second context code is as follows: public class DecAppContext : DbContext { public DecAppContext() // :base("DefaultConnection") { } public DbSet<VignetteModels> VignetteModels { get; set; } public DbSet<VignetteResult> Result { get; set; } } } In my

MVC 6 EF7 RC1 creating multiple dbcontexts

白昼怎懂夜的黑 提交于 2019-12-17 12:36:17
问题 I am trying to figure out how to create a second DB context in EF7 RC1. In the past I could use a constructor with :base("connectionName") but that no longer seems an option since it says cannot convert string to System.IServiceProvider. My second context code is as follows: public class DecAppContext : DbContext { public DecAppContext() // :base("DefaultConnection") { } public DbSet<VignetteModels> VignetteModels { get; set; } public DbSet<VignetteResult> Result { get; set; } } } In my

Entity Framework Core: Log queries for a single db context instance

我是研究僧i 提交于 2019-12-17 10:40:12
问题 Using EF Core (or any ORM for that matter) I want to keep track of the number of queries the ORM makes to the database during some operation in my software. I've used SQLAlchemy under Python earlier, and on that stack this is faily easy to set up. I typically have unit tests that assert on the number of queries made for a scenario, against an in-memory SQLite database. Now I want to do the same thing using EF Core, and have looked at the Logging documentation. In my test setup code I do as

Map category parent id self referencing table structure to EF Core entity

安稳与你 提交于 2019-12-17 09:45:09
问题 Database Table: Image I tried this approach to map the category table to EF core: protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Category>(entity => { entity .HasMany(e => e.Children) .WithOne(e => e.Parent) .HasForeignKey(e => e.ParentId); }); } Entity: [Table("Category"] public class Category : EntityBase { [DataType(DataType.Text), MaxLength(50)] public string Name { get; set; } public int? ParentId { get; set; } public int? Order { get; set; }

How can I call a SQL Stored Procedure using EntityFramework 7 and Asp.Net 5

假如想象 提交于 2019-12-17 06:51:15
问题 For last couple of days I am searching for some tutorials about how to call a Stored Procedure from inside a Web API controller method using EntityFramework 7 . All tutorials I came through are showing it the other way round, i.e. Code First approach. But I already have a database in place and I need to use it to build a Web API . Various business logic are already written as Stored Procedures and Views and I have to consume those from my Web API. Question 1: Is this at all possible to carry

Unable to create migrations after upgrading to ASP.NET Core 2.0

心不动则不痛 提交于 2019-12-17 06:29:00
问题 After upgrading to ASP.NET Core 2.0, I can't seem to create migrations anymore. I'm getting "An error occurred while calling method 'BuildWebHost' on class 'Program'. Continuing without the application service provider. Error: One or more errors occurred. (Cannot open database "..." requested by the login. The login failed. Login failed for user '...'" and "Unable to create an object of type 'MyContext'. Add an implementation of 'IDesignTimeDbContextFactory' to the project, or see https://go