Relative Content

Tag Archive for c#.netentity-frameworkentity-framework-core

How to Make Grouped Query with Specific Key Fields Translatable by EF Core?

I’m working on an application where I need to insert data into a database while avoiding duplicates. To achieve this, I group the imported data by several fields, extract the key fields, and then query the database to check if records already exist. The problem I’m facing is that EF Core isn’t able to translate my query to SQL, resulting in runtime exceptions.

In EF Core 8, why shadow foreign keys still get generated in the table after migration even when I explicitly configure the foreign key?

I have a main entity class PurchasePlanEntity and a detail entity class PurchasePlanDetailEntity, which have a one-to-many relationship. I explicitly defined the foreign key in the DbContext class, but after using migrations, two shadow foreign keys PurchasePlanEntityOrgId and PurchasePlanEntityPurcPlanId were still generated in the table. Additionally, two foreign key constraints FK_purchasePlanDetailEntity_purchasePlan_PurchasePlanEntityPurcPlanId_PurchasePlanEntityOrgId and FK_purchasePlanDetailEntity_purchasePlan_purcPlanId_orgId were created. Why is this happening even though I have explicitly configured the foreign keys?