entity-framework-core

why remove-migration run my app?

末鹿安然 提交于 2019-12-17 04:32:36
问题 I did some version upgrade in last months and now I noticed that when I use "remove-migration" to delete migration that I reverted, it's first run my app. (I noticed that because we do update-database inside startup, so I got to situation where I can't remove migrations, since every time I tried remove migration - it automatically ran the startup which apply the migration to db, then it failed delete it, since it see it in db.) any idea? 回答1: Update for ASP.NET Core 2.1 In ASP.NET Core 2.1

EF Core returns null relations until direct access

﹥>﹥吖頭↗ 提交于 2019-12-16 22:50:11
问题 I have some models like those below: public class Mutant { public long Id { get; set; } ... // Relations public long OriginalCodeId { get; set; } public virtual OriginalCode OriginalCode { get; set; } public int DifficultyLevelId { get; set; } public virtual DifficultyLevel DifficultyLevel { get; set; } } and public class OriginalCode { public long Id { get; set; } ... // Relations public virtual List<Mutant> Mutants { get; set; } public virtual List<OriginalCodeInputParameter>

2 Foreign Keys as Primary Key using EF Core 2.0 Code First

南楼画角 提交于 2019-12-14 03:58:21
问题 I have two tables: Comment and Like . public class Comment { CommentID { get; set; } .... } public class Like { CommentID { get; set; } UserID { get; set; } } Using entity framework core 2.0 code first, I want to define my "Like" model as only having the two fields which reference other primary keys (as foreign keys) but also I want the combination of the values to be the Primary Key of the table. Any help would be appreciated! 回答1: So, here's what's going on here: 1) There are two classes:

Controller Action not triggered - Simple Project - ASP.NET MVC CORE 2.0

无人久伴 提交于 2019-12-14 03:15:39
问题 I have a very simple web application, where I try to let people register a user. Therefore, I try to save user-registration data to Entity Framework, but with no luck. For some reason, IActionResult RegisterUser isn't triggered when submitting a form (I tried setting breakpoints, nothing happened). Can anyone detect why? Startup.cs public class Startup { public void ConfigureServices(IServiceCollection services) { var connection = @"Server=(localdb)\mssqllocaldb;Database=APIExercise2;Trusted

Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'myContext' to type DataContext. error in Azure Function v2

牧云@^-^@ 提交于 2019-12-14 02:35:44
问题 Requirement: Create Azure Function which can inject Entity Framework context to Run method using dependency injection. Here is my Startup class [assembly: WebJobsStartup(typeof(Startup))] namespace MessagesToSqlDbFuncApp { internal class Startup : IWebJobsStartup { public void Configure(IWebJobsBuilder builder) => builder.AddDependencyInjection<ServiceProviderBuilder>(); } } Here is ServiceProviderBuilder class public class ServiceProviderBuilder : IServiceProviderBuilder { public

Solved-Maybe? How to return list of DTO with nested lists of related DTO

假装没事ソ 提交于 2019-12-14 02:35:34
问题 Without using Automapper, I'm trying to map a list of DTO's into each element of a list of DTO's. Specfically in this example, I want the API to return a list of parents where each parent contains it's list of children and list of pets. I have an EF Core project with the models below (which use fully defined relationships) and exist within a larger database. There is a Parent object, which has many Pet objects and many Child objects, like so: EF Core Models public class Parent { public int

Entity Framework Core - Using Stored Procedure with output parameters

左心房为你撑大大i 提交于 2019-12-14 00:17:08
问题 I'm trying to use stored procedures with new Entity Framework Core. I need to start new project soon which will be ASP.Net 5, but not sure if Entity Framework will fit for the job. The application will be triggering several stored procedures per minute and I need output parameters. Will EF be good for this or should I use ADO.Net? I have tried FromSql and database.ExecuteSqlCommand but no luck. using (AppDbContext db = factory.Create()) { var in1 = new SqlParameter { ParameterName = "ParamIn1

DbContext class in .Net Core

99封情书 提交于 2019-12-13 20:19:56
问题 Hi Guys I am trying to migrate from Asp.Net MVC 5 to .Net Core 2.0 Web Application. I am stuck with a error saying : Cannot convert from 'string' to 'Microsoft.EntityFrameworkCore.DbContextOptions' I get the above error when I hover over the class: public class ExampleModelWrapper : DbContext { public ExampleModelWrapper() : base("name=EXAMPLE_MODEL") { } } ExampleModelWrapper is a model. I referred to the following question in stack overflow: How can I implement DbContext Connection String

Entity Framework Core - Include nested list inside list [duplicate]

≡放荡痞女 提交于 2019-12-13 20:18:26
问题 This question already has an answer here : EF Core Second level ThenInclude missworks (1 answer) Closed last year . How can I include an inner list, which is inside another list, in a Entity Framework Core 2.0.1 query? This is what I tried without success: clase = repClase.ListQueryable( //Specification new ApplicationCore.Specifications.ClaseFilterByIdAndIdArticuloWithIncludesSpecification(idClase, idArticuloParam) ) .Include(c => c.ReferenciasConstructor) .ThenInclude(rc => rc.Select(rc1 =>

Conditional WHERE clause on an Entity Framework context

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-13 18:13:42
问题 objRecord = await _context.Persons .Where(tbl => tbl.DeletedFlag == false) .ToListAsync(); This is the EF code I've got which successfully gets all the records from the Person table where DeletedFlag is false. I want to add another where criteria that if a surname has been passed in, then add the extra where clause .Where(tbl => tbl.Surname.Contains(theSurname)) I've tried IQueryable and some other options but can't figure out how to do the equivalent of string theSurname = ""; objRecord =