entity-framework-core

Can't Include navigation property (it is null) [duplicate]

不问归期 提交于 2019-12-24 10:45:37
问题 This question already has answers here : How to stop self-referencing loop in .Net Core Web API? (3 answers) Closed last year . I am trying to get the students from the database and also include the course entities corresponding to them, but it seems that I'm doing something wrong. this is student class: public class Student { public int StudentID { get; set; } public string Name { get; set; } public int CourseID { get; set; } public virtual Course Course { get; set; } } this is course class:

Entity framework Core with Identity and ASP.NET Core RC2 not creating user in database

♀尐吖头ヾ 提交于 2019-12-24 09:40:04
问题 I am working on an application with authentication. I am using the following frameworks: ASP.NET Core RC2 Entity Framework Core The Npgsql EFCore driver For seeding I created a DataSeeder class, that gets added as Transient Service in the ConfigureServices function and later called in the Configure function. It checks whether an IdentityUser exists, and if not it creates one called admin and adds the role Admin to it. However, when adding the role to the user, I get an exception saying that a

Error in migrations in EFCore

↘锁芯ラ 提交于 2019-12-24 09:29:28
问题 When I run Add-Migration using Microsoft.EntityFrameworkCore.Tools 1.1.1, I get the following error: Add-Migration : Exception calling "Substring" with "1" argument(s): "StartIndex cannot be less than zero. Parameter name: startIndex" At line:1 char:1 + Add-Migration + ~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Add-Migration], MethodInvocationException + FullyQualifiedErrorId : ArgumentOutOfRangeException,Add-Migration The same stuff works perfect with version 1.1.0-preview4-final 回答1:

Link ASP.Net Identity table to a user detail table

廉价感情. 提交于 2019-12-24 08:30:33
问题 I am trying to link my Identity user table to a user detail table I have created to track other user information. That user detail table is called UserProfile. I came across this link but it is not working in .NET Core 2.1: Link ASP.NET Identity users to user detail table Here is what I have currently: public class ApplicationUser : IdentityUser { [Key] public override string Id { get; set; } [ForeignKey("Id")] public virtual UserProfile UserProfile { get; set; } } [Table("UserProfile")]

How do I generate EF Core migrations in a Visual Studio 2015 WinForms project?

会有一股神秘感。 提交于 2019-12-24 08:24:09
问题 I am exploring the new Entity Framework Core (NOT in conjunction with ASP.Net, nor under Linux, what I am coding is just a classic WinForms app built with Visual Studio under Windows 7 64-bit using SQLite as the database engine). Trying to reproduce this example I have found out that I need the dotnet.exe tool that is not a part of Visual Studio 2015 and to be installed with .NET Core tools preview for Visual Studio. After having installed it I have faced another error: while trying to

Callback on SaveChanges in EFCore?

五迷三道 提交于 2019-12-24 08:09:13
问题 I'm trying to do something like in my DbContext : public System.Action<IEnumerable<EntityEntry>> OnSave; public override int SaveChanges() { if(OnSave != null) OnSave(ChangeTracker.Entries()); return base.SaveChanges(); } Then DI (AutoFac) the DbContext into another class which can hook into the 'OnSave' function. I'm looking for a single source of truth when this happens. I don't think this will work or be reliable when DbContext is injected into multiple places since I'm pretty sure we end

Projecting an IEnumerable inside an Projected IQueryable making N Requests to the Database

若如初见. 提交于 2019-12-24 08:04:09
问题 I'm making an Asp.net Core Api and one of the Actions of the Controller i need to return an IQueryable of a DTO, but one of the properties is an IEnumerable of another DTO in a relationship one to many in the database model of EF. For example: public class Customer { public int Id { get; set; } public string Name { get; set; } public DateTime Birthday { get; set; } public List<Order> Orders { get; set; } } public class Order { public int OrderNumber { get; set; } public Customer Customer {

.NET Standard 2.0 / EntityFrameworkCore / DB2 / IBM.EntityFrameworkCore issue

泄露秘密 提交于 2019-12-24 07:49:31
问题 Does anyone here has experience with IBM.EntityFrameworkCore package? I've created a .NET Standard 2.0 library project in VS2017, added mentioned package, and tried to make it work by following this and this tutorial from IBM website, with no luck. I get the project compiled, but at the runtime I'm getting a System.TypeLoadException with the following message: Method 'ApplyServices' in type 'IBM.EntityFrameworkCore.Infrastructure.Internal.Db2OptionsExtension' from assembly 'IBM

Using EF Core to invoke stored procedure and closing connection

依然范特西╮ 提交于 2019-12-24 07:39:09
问题 I have an ASP.NET Core 2.2 application using EF Core. I have service class which typically use a DbContext for any CRUD operations. However in one of the method ( Assign method below) I need to use stored procedure. So I am using the following code. Note that DbContext is injected as Scoped instance. public class MyService : IMyService { private readonly MyDbContext _dbContext; public MyService(MyDbContext dbContext) { _dbContext = dbContext; } public async Task<Employee> GetByID(int id) {

How to add new column in Client table in IdentityServer 4 using CodeFirst approach?

笑着哭i 提交于 2019-12-24 07:16:03
问题 I am implementing IdentityServer4. I tried to add new field CustomerId to Client. While doing migration, it is creating new table with name as Client instead of adding new column in Clients table. namespace xx.xx.Models { [Table("Clients")] public class ApplicationClient : Client { public string CustomerId { get; set; } } } 回答1: They don't provide the ability to extend the model in this way. However ClientProperties does exist so you could use that to store custom properties as key/value