entity-framework-core

.NET Entity Framework Core

ぐ巨炮叔叔 提交于 2019-12-10 19:19:03
问题 I've already read through pretty much every other issue regarding EF in that was posted in the past 2 years. I have had no problems downloading other packages, it's only Entity Framework that will not install for me. I've even tried installing the latest version of Nuget and using it's tool inside of my project directory to restore the packages -after- I added a this line to my .csproj: <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.2" /> First I

EF Core Group By translation support on conditional sum

╄→гoц情女王★ 提交于 2019-12-10 18:59:06
问题 I was really excited to hear that EF Core 2.1 will be supporting group by translations. I downloaded the preview and started testing it out but found that I am still not getting group by translations in a number of places. In the code snippet below, the query for TotalFlagCases will prevent the group by translation from working. Is there anyway that I can rewrite this so that I can have group by support? Or perhaps another approach that I can take? There are a lot of rows in this table and I

Entity Framework Core 2.1, ChangeTracker.Tracked

拥有回忆 提交于 2019-12-10 18:53:10
问题 I'm trying to figure out how to use Entity Framework Cores 2.1 new ChangeTracker.Tracked Event to hook into reading queries. Unfortunately, I'm not being able to understand how to implement this. Since it's a new feature it's not possible to find any articles on it and the official Microsoft docs site does not provide any help or sample code. My scenario is pretty simple. I have a database with following columns: id, customerId, metadata. When a user queries this table I want to intercept the

Add modifications to your model when using EF Core DB First Design

大城市里の小女人 提交于 2019-12-10 18:52:48
问题 My team uses Db first design. We create the database, then create the model using the Scaffold-DbContext command. The problem is when we need to modify the model and then do a recreation. public partial class UserInfo { public int Id { get; set; } [Required] public string FirstName { get; set; } public string LastName { get; set; } public string UserName { get; set; } public string Password { get; set; } public DateTime RecordCreated { get; set; } } Upon invoking a Scaffold-DbContext with the

EF 7 (Core). Create DBContext like AddTransient

瘦欲@ 提交于 2019-12-10 18:48:24
问题 According to documents when I configure DbContext like below DI register it in scope (per http request) services.AddEntityFramework() .AddSqlServer() .AddDbContext<DBData>(options => { options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]); } ); The problem appears when I am trying to access it in another thread. public class HomeController : Controller { private readonly DBData _context; public HomeController(DBData context) { _context = context; } public

There is already an object named AspNetRoles in the database. (entity-framework-core)

瘦欲@ 提交于 2019-12-10 18:43:15
问题 I have an asp.net core mvc website using entity framework core. I don't know how it initially happened, but I can't get past the error: "There is already an object named AspNetRoles in the database" I ended up deleted the database, deleting all my migration .cs files and starting from scratch. I've then tried add-migration MyInitialMigration same error I then deleted the database again, and tried a direct update-database (without adding a migration) still the same error I tried changing the

dotnet core on Ubuntu Linux using asp.net MVC and EF MySQL error NU1001: cannot restore MySql.Data.EntityFrameworkCore

拜拜、爱过 提交于 2019-12-10 18:41:29
问题 I've built a simple, flat dotnet core MVC app that I'd like to see running on Linux. It uses EF to pull a few records from a mysql table and display them in a view. It all builds and runs on my host (Win10) but will not in the Ubuntu VM I've spun up to test with After I do a "dotnet restore", I get the following error with "dotnet build" or "dotnet run": Project CoreCrossPlatformFlat (.NETCoreApp,Version=v1.0) will be compiled because the version or bitness of the CLI changed since the last

No service for type 'Microsoft.AspNetCore.Hosting.IHostingEnvironment' has been registered

亡梦爱人 提交于 2019-12-10 18:25:11
问题 I have a problem when I want to fire add-migration command for a ASP MVC Core 2 project. No service for type 'Microsoft.AspNetCore.Hosting.IHostingEnvironment' has been registered. Here is my Startup.cs: public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; } public IConfiguration Configuration { get; set; } public void ConfigureServices(IServiceCollection services) { services.AddDbContextPool<SampleArchContext>((serviceProvider, optionsBuilder)

Entity Framework Core to include different properties from subclasses

本秂侑毒 提交于 2019-12-10 18:19:33
问题 The structure of my classes and repository: public class Group{ //fields } public class User{ public UserRole Role {get;set;} } public abstract class UserRole{ //fields } public class PersonUserRole:UserRole{ public Group Group {get;set;} } public class ManagerUserRole:UserRole{ public IList<Group> Groups {get;set;} } An example where I encounter the issue: public class UserRepository:IUserRepository{ private readonly ApplicationDbContext _dbContext; private readonly DbSet<User> _users;

Entity type 'type' is in shadow-state. A valid model requires all entity types to have corresponding CLR type

浪尽此生 提交于 2019-12-10 18:09:52
问题 I am working from an example to set up IdentityServer4 using Asp.net Core and EF core. During the process I wanted to separate my data contracts and data access from the core project. To do that I created two related projects, one containing the DbContext and one containing the contracts. Eventually I'd like to make things more complicated, but to start I am simply trying to add a related object to the IdentityUser, which is defaulted to ApplicationUser and stored as ApsnetUsers in default