entity-framework-core

How do you configure the DbContext when creating Migrations in Entity Framework Core?

自作多情 提交于 2019-12-28 22:29:27
问题 Is there way that dependency injection can be configured/bootstrapped when using Entity Framework's migration commands? Entity Framework Core supports dependency injection for DbContext subclasses. This mechanism includes allowing for configuration of data access outside of of the DbContext . For example, the following would configure EF to persist to a SQL server using a connection string retrieved from config.json ServiceCollection services = ... var configuration = new Configuration()

What could cause `UserManager` to return the wrong user?

本小妞迷上赌 提交于 2019-12-28 19:28:09
问题 Something rather scary is happening on my ASP.NET Core 2.1.0 MVC site. While I was browsing, all of a sudden it shows I am logged in as a different user (who also happens to be browsing the site at that time). I can't pinpoint whether there is a specific use case that triggers this, but this has happened twice now. Navigating to other pages still shows I am logged in as the other user. It even seems I take over the claims of the user I am incorrectly logged in as. My question is: what could

Populate Created and LastModified automagically in EF Core

十年热恋 提交于 2019-12-28 16:18:10
问题 Looking forward to build a framework, (No repository pattern to working with DbSets directly) to autopopulate Created and last modified automatically, rather than spitting out these codes through out code base. Could you point me out in right direction how to achieve it. In past I tried populating these in constructors, however that seems like a nasty code and every time we pull up somting from database EF change tracking will mark the entity as modified. .ctor() { Created = DateTime.Now;

Self referencing loop from Newtonsoft JsonSerializer using Entity Framework Core

大城市里の小女人 提交于 2019-12-28 07:07:11
问题 I've encountered the error: JsonSerializationException: Self referencing loop detected for property 'Subject' with type 'Project.Models.Subject'. Path 'data[0].Totals'. It occurs when I load a View with a dataGrid populated by an IEnumerable<Subject> model. The Grid is a DevExtreme DataGrid bound to the View's model like this: @(Html.DevExtreme().DataGrid() .DataSource(Model) .Paging(paging => { paging.Enabled(true); paging.PageIndex(0); paging.PageSize(20); }) .Columns(columns => { columns

Error: the entity type requires a primary key

感情迁移 提交于 2019-12-28 05:35:13
问题 I would like to expand the question asked on this thread Binding listbox to observablecollection by giving it an ability to persistent the data. The structure is mostly the same except I installed Entity Framework Core, created a DbContext class to hold the records. I added a button to save the dataset to SQL Server. I did not encounter the compiling error but when I attempted to save the data in the database I got this run time exception: Message=The entity type 'Fruit' requires a primary

Many to many relationship mapping in EF Core

不打扰是莪最后的温柔 提交于 2019-12-28 03:11:09
问题 I have a problem with many to many relationship in EF core. I have the following model classes: public class Meal { public int Id { get; set; } [Required] public int Insulin { get; set; } public MealType Type { get; set; } public ICollection<MealFood> MealFoods { get; set; } public Meal() { MealFoods = new Collection<MealFood>(); } } public class Food { public int Id { get; set; } [StringLength(255)] public string Name { get; set; } [Required] public int Carbohydrates { get; set; } public

Is there an Entity Framework 7 Database-First POCO Generator?

北城以北 提交于 2019-12-27 23:37:06
问题 I've been playing around with Entity Framework 7 and ASP.NET 5 for a new project I'm working on, but I've hit a roadblock. The team I'm working on uses a DBA-first approach to development; i.e. the database is designed by DBA's and then the developers alter the code to compensate for the model changes. Using EF6, this works well, since we can just update the code using the EDMX designer's "update" functionality. One click, we get the new classes, and we're done. However, in EF7, everything is

C# LINQ Select table from list with multiple fields

拥有回忆 提交于 2019-12-25 18:54:11
问题 I'd like to select many values from a table with a list. I have FabricTable (Year is int ): +----+-------+---------+------+ | Id | Color | Texture | Year | +----+-------+---------+------+ | 1 | Red | Rough | 2019 | +----+-------+---------+------+ | 2 | Green | Soft | 2019 | +----+-------+---------+------+ | 3 | Blue | Rough | 2019 | +----+-------+---------+------+ | 4 | Red | Med | 2019 | +----+-------+---------+------+ | 5 | Blue | Soft | 2018 | +----+-------+---------+------+ I have

How to Updgrade MySql for EF core 1.1

时光怂恿深爱的人放手 提交于 2019-12-25 18:39:08
问题 My Original projects.json file is like following: "dependencies": { "Microsoft.NETCore.App": { "version": "1.0.1", "type": "platform" }, "Microsoft.ApplicationInsights.AspNetCore": "1.0.0", "Microsoft.AspNetCore.Mvc": "1.0.1", "Microsoft.AspNetCore.Routing": "1.0.1", "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0", "Microsoft.AspNetCore.Server.Kestrel": "1.0.1", "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", "Microsoft.Extensions.Configuration.FileExtensions": "1.0

error installing Entity Framework Core SqlServer on VS 2017

时光怂恿深爱的人放手 提交于 2019-12-25 12:53:27
问题 Does anyone have any ideas about how to fix this? I have tried it various different ways and version on VS 2015, and then I just recently upgraded to VS 2017, but still have same issue. I'm in the process of installing Entity Framework Core, and wanted to connect to a SqlServer. When I install the package via Pack Man Console or via NuGet interface, I get the following error.... I have the following installed currently.. System.Threading.Thread 4.3.0 provides a compile-time reference assembly