entity-framework-core

Inject ApplicationDbContext into Configure method in Startup

放肆的年华 提交于 2020-05-29 11:52:07
问题 I'm using EntityFrameworkCore 2.0.0-preview2-final and I would like to inject the ApplicationDbContext into Configure method in Startup class. Here's my code: public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, ApplicationDbContext context) { // rest of my code } but when I run my app I'm getting an error message: System.InvalidOperationException: Cannot resolve scoped service 'ProjectName.Models.ApplicationDbContext' from root provider. Here

Visual Studio 2017 using EF Core change local database default location for mdf file before/after migration

时光怂恿深爱的人放手 提交于 2020-05-29 04:37:06
问题 I may need help with the title of my question. So here is more detail. In VS2015 I when creating a database using code first migrations, After completing my first migration I was able to view the database in VS by going to the App_Data folder and clicking on the MDF file. It would then open in Server Explorer. However, in VS2017 I no longer have an App_Data folder and when I did my first migration it took a bit of work to find out where my MDF file was located. If you don't know here are the

Using Entity Framework Core in a Powershell Cmdlet?

↘锁芯ラ 提交于 2020-05-28 06:52:58
问题 Is it possible to build a PowerShell cmdlet that incorporate Entity Framework (Core or EF6) for access to an SQL Server database? I've been writing cmdlets in C# for years, but I've gone through a nightmare the last coupla days trying to use Entity Framework in a project due to what appear to be assembly version clashes. Project has three libraries: MyProject.Commands.dll - cmdlets to load MyProject.Lib.dll - common library code used by the cmdlets MyProject.EF.dll - the Entity Framework

Using Entity Framework Core in a Powershell Cmdlet?

与世无争的帅哥 提交于 2020-05-28 06:52:55
问题 Is it possible to build a PowerShell cmdlet that incorporate Entity Framework (Core or EF6) for access to an SQL Server database? I've been writing cmdlets in C# for years, but I've gone through a nightmare the last coupla days trying to use Entity Framework in a project due to what appear to be assembly version clashes. Project has three libraries: MyProject.Commands.dll - cmdlets to load MyProject.Lib.dll - common library code used by the cmdlets MyProject.EF.dll - the Entity Framework

Avoid Query Client Evaluation error on a query with method definition inside entity class

*爱你&永不变心* 提交于 2020-05-28 03:43:13
问题 In a .NET Core 2.1 project, I'm using EF Core with Command pattern (using MediatR library) on a SQL Server database. I setup the project to avoid client query evaluation, by using these settings: var phaseOptions = new DbContextOptionsBuilder<PhaseDbContext>().UseSqlServer(configuration.GetConnectionString("PhaseDbContext"), sqlServerOptions => sqlServerOptions .EnableRetryOnFailure( maxRetryCount: 5, maxRetryDelay: TimeSpan.FromSeconds(30), errorNumbersToAdd: null)) .ConfigureWarnings

may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints

Deadly 提交于 2020-05-27 12:03:28
问题 Entity Framework Core Throwing error while doing update-database Error:- Introducing FOREIGN KEY constraint 'FK_UserRoleRelationship_UserRoels_ParentUserRoleId' on table 'UserRoleRelationship' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints. Could not create constraint or index. public class UserRoleRelationship { [Key] public int Id { get; set; } [Required] public Guid UserRoleRelationshipId { get; set; }

may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints

时间秒杀一切 提交于 2020-05-27 12:02:33
问题 Entity Framework Core Throwing error while doing update-database Error:- Introducing FOREIGN KEY constraint 'FK_UserRoleRelationship_UserRoels_ParentUserRoleId' on table 'UserRoleRelationship' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints. Could not create constraint or index. public class UserRoleRelationship { [Key] public int Id { get; set; } [Required] public Guid UserRoleRelationshipId { get; set; }

may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints

浪尽此生 提交于 2020-05-27 12:01:31
问题 Entity Framework Core Throwing error while doing update-database Error:- Introducing FOREIGN KEY constraint 'FK_UserRoleRelationship_UserRoels_ParentUserRoleId' on table 'UserRoleRelationship' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints. Could not create constraint or index. public class UserRoleRelationship { [Key] public int Id { get; set; } [Required] public Guid UserRoleRelationshipId { get; set; }

may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints

时光总嘲笑我的痴心妄想 提交于 2020-05-27 12:01:29
问题 Entity Framework Core Throwing error while doing update-database Error:- Introducing FOREIGN KEY constraint 'FK_UserRoleRelationship_UserRoels_ParentUserRoleId' on table 'UserRoleRelationship' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints. Could not create constraint or index. public class UserRoleRelationship { [Key] public int Id { get; set; } [Required] public Guid UserRoleRelationshipId { get; set; }

EF Core linq and conditional include and theninclude problem

萝らか妹 提交于 2020-05-25 07:42:44
问题 I am having a problem with getting a result when trying to get objects with multiple levels. This is what I am trying to do roughly: _context.Investors.Where(s => s.Id == userId) .Include(c => c.Coins) //only want this if some kind of flag is given by the user. .ThenInclude(ct => ct.CoinType) .Include(c => c.Bricks) //only want this if some kind of flag is given by the user. Essentially I am getting a lot of flags indicating if I should include parts of the object. I got it almost to work.