Forum Widgets
Latest Discussions
EF Core : foreign key column with same name as existing navigation property
I want to use EF Core to map a legacy database. I cannot scaffold as there are hundreds of tables and I am only interested in very few and besides scaffolding generates names for the navigation properties which are not the ones I want. The situation is: I have a required many-to-one relationship linked by a column name that matches the name of the property that I want to give. The code (simplified) is: public class EntityProperty { public ControlType ControlType { get; set; } } public class ControlType { public List<EntityProperty> Properties { get; set; } = new List<EntityProperty>(); } Nothing more is required, eg, I'm not using foreign key properties, just navigation. The problem is, the foreign key column from the EntityProperties table to the ControlTypes is also called ControlType. So, when I try to map it as: builder.HasOne(x => x.ControlType) .WithMany(x => x.Properties) .IsRequired() .HasForeignKey("ControlType"); I want to use EF Core to map a legacy database. I cannot scaffold as there are hundreds of tables and I am only interested in very few. The situation is: I have a required many-to-one relationship linked by a column name that matches the name of the property that I want to give. The code (simplified) is: public class EntityProperty { public ControlType ControlType { get; set; } } public class ControlType { public List<EntityProperty> Properties { get; set; } = new List<EntityProperty>(); } The problem is, the foreign key column from the EntityProperties table to the ControlTypes is also called ControlType. So, when I try to map it as: builder.HasOne(x => x.ControlType) .WithMany(x => x.Properties) .IsRequired() .HasForeignKey("ControlType"); I get the following exception: InvalidOperationException: The property or navigation 'ControlType' cannot be added to the 'EntityProperty' type because a property or navigation with the same name already exists on the 'EntityProperty' type.' The problem is with HasForeignKey, I guess it's because I am adding a shadow property when a "physical" property already exists, but I what I really mean to say is to use a different column name to link the two entities: what I want is to be able to specify a "not standard" column name for the foreign key, which I am not able to. I do not have a foreign key property, only a navigation property, and I do not want to have one.SolvedRicardo PeresMay 20, 2024Copper Contributor2.4KViews0likes1CommentHow do create a matrix formula to calculate in all range (B:F) with this rare condition.
Bom dia família, Preciso criar uma fórmula matricial para calcular quantas vezes essa coincidência aparece em todo o intervalo B:F , de acordo com essas condições ( A) na primeira linha ), ( M) na segunda linha ). Tentei com essas 2 fórmulas, mas conta apenas uma coincidência. Alguém tem alguma sugestão por favor? Desde já, obrigado.SolveddpparnerJan 17, 2022Copper Contributor5.8KViews0likes10Comments
Resources
Tags
- Entity Framework Core8 Topics
- ADO.NET7 Topics
- SqlClient7 Topics
- entity framework6 Topics
- ASP.NET Core1 Topic
- SQLite1 Topic