entity-framework

Insert new record in pivot table with many to many relationship using Entity Framework Core

℡╲_俬逩灬. 提交于 2021-02-10 06:22:35
问题 I am building an application using ASP.NET Core MVC. I am trying to insert a new record with a many-to-many relationship. I have 3 tables Repairs , Parts and RepairParts . How can I insert the RepairId and PartId into the RepairParts table? Does EF Core provide something for this? I searched the documentation but it doesn't mention anything about how to do this. Does Entity Framework do this automatically? (insert to the pivot table) Or do I need to do it manually? An example would help.

How to use Add-Migration if the project contains multiple folders

佐手、 提交于 2021-02-10 06:17:15
问题 I would like to Add-Migration with my DbContext, but I get Error: The term 'add-migration' is not recognized as the name of a cmdlet, function, script file, or operable program. Is the problem related with folder structure? The customized User.cs, Role.cs and the Startup.cs are in different folders. The Entity Framework is included in the DbContext project file. How do I fix this? 回答1: Is the problem related with folder structure? This issue is not about the folder structure .It's about the

Return parents with null children using C# EF Core .Include

房东的猫 提交于 2021-02-10 05:23:11
问题 Our goal is to query a database, using Entity Framework Core and the .Include(...) extension method to return a collection of objects that have a child, where some of the children will be null. We have a table Projects with a C# model Project and a table Locations with a C# model Location . Each Project has a one or zero Location objects and the objects look like this: public class Project { public string LocationId { get; set; } public Location Location { get; set; } } public class Location

Catching calling method name in IDbCommandInterceptor

旧巷老猫 提交于 2021-02-10 05:06:34
问题 I am using IDbCommandInterceptor to catch Entity Framework queries. This way I can access some crucial information such as DbParameter s and DbCommand etc. Bu I also need to get where this query is called from. I have tried to get this by by using StackTrace : StackTrace stackTrace = new StackTrace(); System.Reflection.MethodBase methodBase = stackTrace.GetFrame(1).GetMethod(); This might work in regular method calls, but in this instance since I am intercepting the Entity Framework mechanism

Catching calling method name in IDbCommandInterceptor

*爱你&永不变心* 提交于 2021-02-10 05:05:36
问题 I am using IDbCommandInterceptor to catch Entity Framework queries. This way I can access some crucial information such as DbParameter s and DbCommand etc. Bu I also need to get where this query is called from. I have tried to get this by by using StackTrace : StackTrace stackTrace = new StackTrace(); System.Reflection.MethodBase methodBase = stackTrace.GetFrame(1).GetMethod(); This might work in regular method calls, but in this instance since I am intercepting the Entity Framework mechanism

Entity framework database provider compatibility error

社会主义新天地 提交于 2021-02-09 14:00:28
问题 I am trying to use Entity framework to setup an ADO.net model using MYSQL DB following the instructions @https://dev.mysql.com/doc/connector-net/en/connector-net-entityframework60.html,I installed the connector and stuck at the below error,I shared my App.config details aswell,can anyone help me on how to fix this error? App.config <?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com

Seeding Many-To-Many data

元气小坏坏 提交于 2021-02-09 07:13:25
问题 Hello I'm trying to create some seeds for my project, but I'm having trouble seeding the Many-To-Many relationship data to the db. My database looks like this: in TeacherSkills , Teacher_ID and Skill_ID are foreign keys for their tables ofcourse. My seeder looks like this protected override void Seed(Ability_Examen_ASP.Models.AbilityDbContext context) { if (!context.Skills.Any()) { context.Skills.Add(new Models.Skill { SkillName = "PHP" }); context.Skills.Add(new Models.Skill { SkillName =

Change IdentityServer4 Entity Framework table names

痞子三分冷 提交于 2021-02-08 18:49:39
问题 I am trying to change the default table names created by the PersistedGrantDb and ConfigurationDb for IdentityServer4 and have Entity Framework generate the correct SQL. For example; instead of the using the entity IdentityServer4.EntityFramework.Entities.ApiResource using the table ApiResources , I want the data to be mapped into a table named mytesttable According to the documentation this should be as simple as adding ToTable invocations for each entity that I want to remap in the

Change IdentityServer4 Entity Framework table names

走远了吗. 提交于 2021-02-08 18:46:01
问题 I am trying to change the default table names created by the PersistedGrantDb and ConfigurationDb for IdentityServer4 and have Entity Framework generate the correct SQL. For example; instead of the using the entity IdentityServer4.EntityFramework.Entities.ApiResource using the table ApiResources , I want the data to be mapped into a table named mytesttable According to the documentation this should be as simple as adding ToTable invocations for each entity that I want to remap in the

Change IdentityServer4 Entity Framework table names

蓝咒 提交于 2021-02-08 18:40:22
问题 I am trying to change the default table names created by the PersistedGrantDb and ConfigurationDb for IdentityServer4 and have Entity Framework generate the correct SQL. For example; instead of the using the entity IdentityServer4.EntityFramework.Entities.ApiResource using the table ApiResources , I want the data to be mapped into a table named mytesttable According to the documentation this should be as simple as adding ToTable invocations for each entity that I want to remap in the